Why does the Elastic Search API ignore our query limit?

I am using this code:

client.prepareSearch("test").addSort("dateUpdated", SortOrder.DESC) .setSearchType(SearchType.DFS_QUERY_AND_FETCH) .setIndices("reach") .setTypes(types) .setQuery(QueryBuilders.queryString(queryString)) .setFrom(0).setSize(2).setExplain(true) .execute() .actionGet() 

A client is a remote client. There are 5 general results based on what I have above, I expect only two results. But all 5 are coming back. IF I set size 0, nothing returns (as expected) What am I missing? I feel like I'm misunderstanding something about things from / size. My query string is just "name: *". Any help is much appreciated!

+6
source share
1 answer

Here is another explanation of how to set the size without worrying about the number of fragments. http://elasticsearch-users.115913.n3.nabble.com/About-setsize-Java-API-td3216996.html

"query and fetch" is the fastest type of search, but it suffers from this problem of getting a given size for each fragment. Using "query then fetch" will solve the problem. It is also the default search type if none are specified.

More on search types: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-search-type.html

+9
source

All Articles