Elastic search size unlimited

New for resilient search. There is a problem writing a search query that returns all matching records in my collection. Below is my record search request

{
   "size":"total no of record" // Here i need to get total no of records in collection
   "query": {
      "match": {
         "first_name": "vineeth"
      }
   }
}

By running this query, I get a maximum of 10 entries, I am sure that there are more than 10 matching entries in my collection. I searched a lot and finally got the size parameter in the request. But in my case, I do not know the total number of entries. I think that providing an unlimited number for a variable size is not good practice, so how to manage this situation please help me solve this problem, thanks

+4
source share
3 answers

, from size, . , ( 10 ) :

{
    "from": 0,
    "size": 10,
    "query": {
        "match": {
            "first_name": "vineeth"
        }
    }
}

, size . , , hits.total ( ) .

+5

To get all entries, for each document you have to use scrolling. Here is the document: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html

But the idea is to indicate your search and indicate that you want to scroll it:

curl -XGET 'localhost:9200/twitter/tweet/_search?scroll=1m' -d '
{
   "query": {
    "match" : {
        "title" : "elasticsearch"
     }
 }
}'

In the scroll parameter, you specify how long you want the search results to be available.

Then you can get them with the returned scroll_id and scroll api.

+3
source

Source: https://habr.com/ru/post/1531763/


All Articles