elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

deserializing co.elastic.clients.elasticsearch.core.search.Hit: jakarta.json.JsonException: Jackson exception (JSON path: hits.hits[0]._source) (line no=1, column no=250, offset=-1)

Open Aiox123 opened this issue 1 year ago • 2 comments

Java API client version

8.6.0

Java version

11

Elasticsearch Version

8.6.0

Problem description

    List<NoteDoc> result = new ArrayList<>();
    MatchAllQuery query = QueryBuilders.matchAll().build();
    SearchRequest request = new SearchRequest.Builder()
            .index(ES_NOTE_INDEX)
            .query(query._toQuery())
            .build();
    try {
        SearchResponse<NoteDoc> search = elasticsearchClient.search(request, NoteDoc.class);
        for (Hit<NoteDoc> hit : search.hits().hits()) {
            log.info("Note: {}",hit.source());
            result.add(hit.source());
        }
        return RestResponse.success(result);
    } catch (IOException e) {
        log.error(e.getMessage());
        TravelNoteException.cast(e.getMessage());
    }

Aiox123 avatar Jun 15 '23 14:06 Aiox123

Java entity classes need to add constructors, and Jackson deserialization needs to go through the constructor of entity classes.

Aiox123 avatar Jun 15 '23 14:06 Aiox123

I guess "entity class" is NoteDoc? This seems like a problem in the configuration of Jackson. We need more details to confirm that.

Can you test the deserialiation of JSON data in the NoteDoc class with Jackson independently of the Elasticsearch client ?

swallez avatar Jun 21 '23 17:06 swallez

Hello, is this still an issue? I'll close this otherwise.

l-trotta avatar Apr 18 '24 15:04 l-trotta