eric
eric

Reputation: 2759

Why is the Elastic Search java API ignoring 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()

The client is a remote client. There are 5 total results, based on what I have above, I only expect two results to come back. Yet all 5 come back. IF I set the size to 0, nothing comes back (as expected) What am I missing? I feel like I am misunderstanding something about the from/size stuff. My query string is just "name:*". Any help is greatly appreciated!

Upvotes: 6

Views: 5605

Answers (1)

grasskode
grasskode

Reputation: 158

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

"query and fetch" is the fastest search type but suffers from this problem of fetching the specified size per shard. Using "query then fetch" will solve the problem. It is also the default search type when none is specified.

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

Upvotes: 9

Related Questions