Home > other >  ElasticSearch: How to search only the N docs for large scale index?
ElasticSearch: How to search only the N docs for large scale index?

Time:10-13

I have large number of docs(about 100M) stored in a single index, when using group by on single field, the query may eat up all my CPU on ES server(most of time, < 100 results returned).

Is it possible to limit the query scope(i.e., only search 1M docs) for a single query?

CodePudding user response:

Use query pagination to limit the search scope:

GET /_search
{
  "from": 0,
  "size": 1000000,
  "query": {
    "match": {
      "city": "New york"
    }
  }
}

more information in documentation

CodePudding user response:

to add to the other answer, you can also look at https://www.elastic.co/guide/en/elasticsearch/reference/7.15/search-aggregations-bucket-sampler-aggregation.html

  • Related