elasticsearch-java
elasticsearch-java copied to clipboard
null value in sort hit response causes parsing failure - throws nullpointerexception
Java API client version
7.17.6
Java version
17
Elasticsearch Version
7.17.6
Problem description
I am migrating elasticsearch from old to new elasticsearch java client.
I encounter this problem wherein I issue a request query, then the response has null
values.
The code below is how I request:
SearchRequest request = requestBuilder.build();
SearchResponse<ObjectNode> response;
try {
response = elasticCLient.search(request, ObjectNode.class);
} catch (final IOException e) {
throw Exception(e);
}
As you can see it uses ObjectNode.class
Problem arises when the response has null
value.
A null pointer exception happens which I think the response cannot be serialized because of the null
value.
The response when viewed in kibana is like this:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "robots_20220613111538",
"_type" : "_doc",
"_id" : "2",
"_score" : null,
"_source" : {
"path" : "C:/storage/1",
"name" : "barbie.jpg",
"collection" : [ ]
},
"sort" : [
null,
"barbie.jp",
1664377265000
]
},
{
"_index" : "robots_20220613111538",
"_type" : "_doc",
"_id" : "3",
"_score" : null,
"_source" : {
"path" : C:/storage/1",
"name" : "hellokitty.jpg",
"collection" : [ ]
},
"sort" : [
null,
"hellokitty.jpg",
1664377266000
]
}
]
}
}
How to deal with this kind of response?
Are there other ways instead of using ObjectNode.class
?
Any help is greatly appreciated.
This causes the exception because of the null
value
This is a sort field response from a query
"sort" : [
null,
"barbie.jp",
1664377265000
]
This could possibly the cause?
This list is with elements nulls and the serialization broken.
https://github.com/elastic/elasticsearch-java/blob/8e4db1dea8897d3acfca72ab501be7c0bca91e5b/java-client/src/main/java/co/elastic/clients/elasticsearch/core/search/Hit.java#L763
This was the fix in 7.16.2
But it still throws NullPointerException when hits.toString() is called
Currently I am using 7.17.6
Hello, thank you for reporting this! I have tried reproducing the issue using an updated version of the 7.17 client, and it seems to be working fine for me. Could you let me know if updating the client solves this issue? Thanks again!
Is there a fix for it?
@imjuoy which version are you using? version 2.3.0 of this client doesn't exist