my code is as below:
sr = client.prepareSearch(lastIndex)
.setQuery(boolQueryBuilder)
.setRouting(elasticRouting)
.addSort("startTime", SortOrder.DESC)
.execute().actionGet();
the above code will get two hits, but when I add "setSize(1)", as below:
sr = client.prepareSearch(lastIndex)
.setQuery(boolQueryBuilder)
.setRouting(elasticRouting)
.addSort("startTime", SortOrder.DESC)
**.setSize(1)**
.execute().actionGet();
I get no hits. I want to limit return results to 1, am I doing it wrong?
dadoonet
(David Pilato)
November 28, 2016, 8:21am
2
Please format your code using </>
icon. It will make your post more readable.
My guess is that it is related to routing although it should not be an issue here.
Can you reproduce this behavior with a pure full REST script so we can see if it's a bug?
The weird thing is when I using restful request, the result is normal, it returns exactly one hit.
here is my post request:
POST /service/_search?routing=id
{
"query": {
"bool": {
"filter": {
"term": {
"id": "4785SERTDDSSER322"
}
},
"must": {
"exists": {
"field": "startTime"
}
},
"should": [{
"bool": {
"must_not": {
"exists": {
"field": "status"
}
}
}
},
{
"term": {
"status": ""
}
}]
}
},
"sort": {
"startTime": {
"order": "desc"
}
},
"size": 1
}
dadoonet
(David Pilato)
November 29, 2016, 2:37am
4
So can you not call execute().get() but call toString() and paste the result here in both cases?
I think I figure out the issue. it is because I just insert the data and get it immediately in my test, the data is not sync yet, but after I make it wait 2 seconds, and then get the result again, the result is fine.
dadoonet
(David Pilato)
November 29, 2016, 10:50am
6
Then prefer using refresh feature instead of "waiting" for x seconds.
But please do that only in tests
system
(system)
Closed
December 27, 2016, 10:50am
7
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.