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!
By default, Elasticsearch limits the number of results to 10, so if you can have more than 10 results, look at the value of total for the precise number of documents that match your search criteria. As you saw previously, to change the number of results returned, use the size parameter.
The size parameter is the maximum number of hits to return. Together, these two parameters define a page of results. response = client.
Elasticsearch is a real-time distributed and open source full-text search and analytics engine. It is used in Single Page Application (SPA) projects. Elasticsearch is an open source developed in Java and used by many big organizations around the world. It is licensed under the Apache license version 2.0.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With