Hi all,
I am currently in the progress of migrating our code to be compatible with ES 5.4 (we came from 2.3)
I am using the Java API as described in the elasticsearch documentation (5.4) but came across something weird.
So the start situation in 2.3 was this query:
String searchString = "{\n" + " \"from\": <START_FROM>,\n" + " \"size\": <RESULTS_SIZE>,\n" + " \"query\": {\n" + " \"term\": {\n" + " \"" + fieldName + "\": \"" + fieldValue + "\"\n" + " }\n" + " }\n" + "}";
So from and size were replaced and we had a working query.
However I am currently using the wrapperQueryBuilder as per the documentation of 5.4.
So I get the following statement:
SearchResponse result = this.client.prepareSearch(index).setSource(new SearchSourceBuilder().query(new WrapperQueryBuilder(finalString))).get();
The query also had to be rewritten as follows (note the missing keywords query, from , size):
private String getSearchString(String fieldName, String fieldValue){ String searchString = "{\n" + " \"term\": {\n" + " \"" + fieldName + "\": \"" + fieldValue + "\"\n" + " }\n" + "}"; return searchString; } String finalString = searchString.replaceAll("<START_FROM>", String.valueOf(startFrom)).replaceAll("<RESULTS_SIZE>", String.valueOf(resultsSize));
Now my question is, how do you pagination with the Java WrapperQueryBuilder / SearchSourceBuilder / SearchRequestBuilder?
I discovered that SearchSourceBuilder has a method setFrom(int), but is there a way to set the size for the result ? I've been looking but can't seem to find it.
Any help would be greatly appreciated.