Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch count returned result

I want to count number of document returned as a result of a query with size limit. For example, I run following query:

curl -XGET http://localhost:9200/logs_-*/a_logs/_search?pretty=true -d '
{
"query" : {
    "match_all" : {  }
},
"size" : 5,
"from" : 8318
}'

and I get:

{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 159,
"successful" : 159,
"failed" : 0
},
  "hits" : {
  "total" : 8319,
  "max_score" : 1.0,
  "hits" : [ {
....

Total documents matching my query are 8319, but I fetched at max 5. Only 1 document was returned since I queried "from" 8318.

In the response, I do not know how many documents are returned. I want to write a query such that the number of documents being returned are also present in some field. Maybe some facet may help, but I could not figure out. Kindly help.

like image 911
Nabeel Akhtar Avatar asked May 15 '13 12:05

Nabeel Akhtar


People also ask

How do I get total hits in Elasticsearch?

The track_total_hits parameter allows you to control how the total number of hits should be tracked. Given that it is often enough to have a lower bound of the number of hits, such as "there are at least 10000 hits", the default is set to 10,000 .

How check count in Kibana?

Create "topN" query on "clientip" and then histogram with count on "clientip" and set "topN" query as source. Then you will see count of different ips per time.

What is Docs count in Elasticsearch?

The doc. count represents the number of documents indexed in your index while index_total stands for number of indexing operations performed during elasticsearch uptime.


1 Answers

Your query :

{
"query" : {
    "match_all" : {  }
},

=> Means that you ask all your data

"size" : 5,

=> You want to display only 5 results

"from" : 8318

=> You start from the 8318 records

ElasticSearch respons :

....

"hits" : {
  "total" : 8319,

... => Elastic search told you that there is 8319 results in his index.

You ask him all the result and you start from the 8318.

8319 - 8318 = 1 So you have 1 result.

Try by removing the from.

like image 89
toto Avatar answered Nov 07 '22 13:11

toto