Karthikeyan
Karthikeyan

Reputation: 2001

Kibana query results mismatch between _count & _search api

Am executing below kibana query, when i execute _count api am getting count:45. But if i execute same query with _search api on the same index, am getting only 10 documents in response instead of 45 documents

Please find the below kibana query

GET documents_test2/_count
{
    "query": {
        "query_string" : {
            "default_field" : "*",
            "query" : "40011"
        }
    }
}

For the above Kibana query am getting below response with the count:45

{
  "count": 45,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  }
}

But if i execute the below query with _search api instead of _count am getting only 10 doucuments in response

GET documents_test2/_search
{
    "query": {
        "query_string" : {
            "default_field" : "*",
            "query" : "40011"
        }
    }
}

Upvotes: 0

Views: 158

Answers (1)

lrathod
lrathod

Reputation: 1124

This is because, when your use "_search" , it uses "size" param to return the no. of relevant documents. and since you are not passing that param here, it default value is passed , which is 10. hence only 10 documents are return.

Pass "Size" param value to return as many documents you want.

GET documents_test2/_search
{
   "size" : 45,
   "query": {
     "query_string" : {
        "default_field" : "*",
        "query" : "40011"
    }
}

You can also check "From" param to get the paginated results (sliding window) from elastic search. e.g. if you want to get 3rd page documents with page size as 10, you can pass "Size" : 10 , "From" : 20 (i.e. pagesize X (pageno. - 1) = 10 * (3-1) = 10 X 2 = 20

Check https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html for more details.

Upvotes: 1

Related Questions