Java client version upgrade causing issues


(Pradeep Sadashivamurthy) #1

I have upgraded Java client from 1.3.1 version to 1.3.4 but the order of search results are not what I was expecting (in a random order). I tried with many times reverting back and forth the version. All good until 1.3.2 version but after 1.3.3 the search result oder is not same as the search result order of 1.3.2. I have gone through the release notes doesn't give a clue.

Eg:

INDEX:
curl -XPUT 'http://localhost:9200/default-index/DummyObject/1' -d '{ "id" : "first", "name" : "INDIVIDUAL" }'
curl -XPUT 'http://localhost:9200/default-index/DummyObject/2' -d '{ "id" : "second", "name" : "individual" }'
curl -XPUT 'http://localhost:9200/default-index/DummyObject/3' -d '{ "id" : "third", "name" : "IndIVIDUAL" }'

SEARCH:
curl -XGET 'http://localhost:9200/default-index/DummyObject/_search' -d '{"query":{"match_all":{}}}'

The result until version 1.3.2 is "first, second and third" but after version 1.3.3 it is "third, first and second". I was expecting / want the result to be "first, second and third". Please help. Thanks


(Nik Everett) #2

So the sort order of match_all is pretty undefined. Its just whatever order it was read back in the index and whatever order the coordinating node decided to merge the results. In this case I'm not surprised that the order changed. I'm more surprised that it was consistent for you for so long.


(David Pilato) #3

If you want to sort your results, then you have to add a sort.

You are running a match_all here with default sorting by _score. Each score is 1 so you can not say that you expect 1 before 2 or 2 before 3.

It depends. May be they can come back in the order you expect if you have only one shard, but I would definitely not rely on that and add a proper sort.

My cents.


(Pradeep Sadashivamurthy) #4

Nik, David,

Thanks for the reply. I was trying to debug the behaviour further. For the same request, response from curl is different from Java client. The scores are also different. The requests and responses for Java client and Curl are as follows. The java client versions 1.3.2 and 1.3.1 has the same response as the curl response. Trying to understand why are they different.

Java Client Request:
{
"bool" : {
"should" : [ {
"match" : {
"name" : {
"query" : "name",
"type" : "boolean"
}
}
}, {
"match" : {
"name" : {
"query" : "INDIVIDUAL",
"type" : "boolean"
}
}
} ]
}
}
Java Client Response:
{
"took":38590,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"hits":{
"total":3,
"max_score":0.11447419,
"hits":[
{
"_index":"default-index",
"_type":"com-thomsonreuters-grc-platform-util-searching-elasticsearch-DummyObject",
"_id":"third",
"_score":0.11447419,
"_source":{
"id":"third",
"name":"IndIVIDUAL",
"version":0,
"creationDateInMillis":0
}
},
{
"_index":"default-index",
"_type":"com-thomsonreuters-grc-platform-util-searching-elasticsearch-DummyObject",
"_id":"first",
"_score":0.11447419,
"_source":{
"id":"first",
"name":"INDIVIDUAL",
"version":0,
"creationDateInMillis":0
}
},
{
"_index":"default-index",
"_type":"com-thomsonreuters-grc-platform-util-searching-elasticsearch-DummyObject",
"_id":"second",
"_score":0.11447419,
"_source":{
"id":"second",
"name":"individual",
"version":0,
"creationDateInMillis":0
}
}
]
}
}

So I tried to create a same request from curl

Curl Request
curl -XGET http://localhost:9200/default-index/_search -d '{"query":{"bool":{"should":[{"match":{"name":{"query":"name","type":"boolean"}}},{"match":{"name":{"query":"INDIVIDUAL","type":"boolean"}}}]}}}'

Curl Response
{
"took":70,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"hits":{
"total":3,
"max_score":0.09848769,
"hits":[
{
"_index":"default-index",
"_type":"com-thomsonreuters-grc-platform-util-searching-elasticsearch-DummyObject",
"_id":"first",
"_score":0.09848769,
"_source":{
"id":"first",
"name":"INDIVIDUAL",
"version":0,
"creationDateInMillis":0
}
},
{
"_index":"default-index",
"_type":"com-thomsonreuters-grc-platform-util-searching-elasticsearch-DummyObject",
"_id":"second",
"_score":0.09848769,
"_source":{
"id":"second",
"name":"individual",
"version":0,
"creationDateInMillis":0
}
},
{
"_index":"default-index",
"_type":"com-thomsonreuters-grc-platform-util-searching-elasticsearch-DummyObject",
"_id":"third",
"_score":0.04500804,
"_source":{
"id":"third",
"name":"IndIVIDUAL",
"version":0,
"creationDateInMillis":0
}
}
]
}
}


(system) #5