ElasticSearch generic url only 10 item return - elasticsearch

Is there a reason that a generic search on a index only returns 10 items?
If so how can I set the limit higher?
http://localhost:9200/journal/_search

10 is just the default number of search hits that will get returned. Take a look here https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html
There you find a lot of parameters to append to your URI Search. You need to set the size parameter like so:
http://localhost:9200/journal/_search?size=100

Related

Elasticsearch result count shows less than what it should be

I'm not sure why when I search for the documents from an index I'm only getting 10 when it tells me I have more. From the image below you can see that it says there are 45 hits but when I count the number of hits it's far less than that.
The command I used to grab the documents is:
curl -XGET http://localhost:9200/contextual_original/_search/?pretty
I know the count of 45 is correct but I'm not sure why only 10 of them are showing up. Does anyone know what I'm missing here?
By default, elasticsearch limits the number of results that match your search to 10.
You must set the size parameter if you want to obtain more hits. The "size" parameter is used to provide the maximum number of results for a search that you want to return.
Modify your command as shown below (for suppose you want to retrieve 20 documents)
curl -XGET http://localhost:9200/contextual_original/_search/?size=20&pretty

Increasing number of returned documents from ctx.payload loop in watcher api - Elasticsearch

In my watcher, I am iterating over returned documents via the {{#ctx.payload.hits.hits}} ... {{/ctx.payload.hits.hits}} notation. It is working properly however only returning the top 10 documents in the payload. If I have a payload of size > 10, then it will only iterate over the first 10 documents.
Is there any config somewhere in which I can adjust what I imagine the default amount of 10 is to something else?
Thanks in advance.
The search body request may contain a size parameter that specifies the number of documents to retrieve. If this parameter is not set, this value defaults to 10.
Since, The action access the result of the query only, you see only these 10 documents.
In order to retrieve more documents you have to set this parameter to the desired value, e.g., 100 (note that there is an upper bound) in the query portion of the watcher.

Pagination with multi match query

I'm trying to figure out how to accomplish pagination with a multi match query using elasticsearch.
The scroll and search_after APIs seem like they won't work. scroll isn't meant for real time user requests as per documentation. search_after requires some unique field per id and requires you to sort on that field as per documentation but when using a multi-match query you're basically sorting by the score.
So, the only thing I've thought of so far is to do the following:
Send back last document id + score and use the score as the sort field. But, this could potentially return duplicate documents if other documents were added in between two queries.
If you want to paginate the first option is to use from and size parameter in your query. The documentation here
Pagination of results can be done by using the from and size
parameters. The from parameter defines the offset from the first
result you want to fetch. The size parameter allows you to configure
the maximum amount of hits to be returned.
Though from and size can be set as request parameters, they can also
be set within the search body. from defaults to 0, and size defaults
to 10.
Note that from + size can not be more than the index.max_result_window
index setting which defaults to 10,000. See the Scroll or Search After
API for more efficient ways to do deep scrolling.
If you don't need to paginate over 10k results it's your best choice. The max_result_window can be modified, but the performance will decrease as the selected page number will increase.
But of course if some documents are added during your user pagination they will be added and your pagination can be slightly inaccurate.

In Elastic Search how can I get result from each types in an index for result limited to 10 query.?

I have four types in my index and I am searching for a keyword and the result is limited to 10.I need to get records from all types.Is it possible.?
If you mean getting the first 10 docs per type, I'd use the multisearch API.
See https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-multi-search.html

How to get all the values from an search result

I am new to Elastic Search. Is there any way to get all the search results for a search keyword? Elastic Search is limited to 10 or else we can set the size but we need to get the size??
Yes, the default number of search results is 10.
You need to set the size parameter on the query.
I don't think you an say "all results", though, there must always be a size limit.
If you use the JAVA API you can simple get the total hit number from the SearchResponse
SearchRequestBuilder srb = ..
SearchResponse sr = srb.execute().actionGet();
long totalHits = sr.getHits().getTotalHits();
You can do this in couple of steps using some code
Fix a size say 1000 and get all 1000 records.
Identify from hits.total whether size is smaller than 1000. (if small then you got all the records :) )
Otherwise use from and size to provide 1001 in from and total as size from previous query to get full result.

Resources