Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 289
eric Avatar asked Jan 28 '13 18:01

eric


People also ask

How do I limit Elasticsearch results?

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.

What is Elasticsearch query size?

The size parameter is the maximum number of hits to return. Together, these two parameters define a page of results. response = client.

What is elastic search in Java?

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.


1 Answers

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

like image 126
grasskode Avatar answered Sep 28 '22 03:09

grasskode