Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch query returns 10 when expecting > 10,000

I want to retrieve all the JSON objects in Elasticsearch that have a null value for awsKafkaTimestamp. This is the query I have set up:

{
  "query": {
    "bool": {
      "must_not": {
        "exists": {
          "field": "tracer.awsKafkaTimestamp"
        }
      }
    }
  }
}

When I curl to my elasticsearch endpoint with the DSL I only get a few values back. I am expecting all (10000+) of them because I know for sure all the awsKafkaTimestamp values are null

This is the response I get when I use Postman. As you can see, there are only 10 JSON objects returned to me:

enter image description here

like image 762
Liondancer Avatar asked Oct 18 '25 15:10

Liondancer


2 Answers

It's correct behaviour of the elasticsearch. By default, it only returns 10 records and provides information in hits.total field about the total number of documents matching search criteria. To retrieve more data than 10 you should specify size field in your query as shown below (you can read more about it here: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html):

{
    "from" : 0, "size" : 10,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}
like image 110
Adam Łepkowski Avatar answered Oct 21 '25 14:10

Adam Łepkowski


By default elasticsearch will give you 10 results, even if it matches to 10212. You can set the size parameter but that is limited to 10000, so your only option is to use the scroll API to get,

Example from elasticsearch site Scroll API

curl -XGET 'localhost:9200/twitter/tweet/_search?scroll=1m' -d '
{
    "query": {
        "match" : {
            "title" : "elasticsearch"
        }
    }
}
'
like image 26
Hkntn Avatar answered Oct 21 '25 12:10

Hkntn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!