How to get count of document with its range using DSL query


(Saineshwar Bageri) #1

I want count of document between particular range.
if i take appstatusid from range 1 to 500 then count of document will be 500.

Document Sample "Indexname" :applicationstatus and unique id which i am inserting is "appstatusid"

[{
"_index": "applicationstatus",
"_type": "data",
"_id": "WaqQ0mEBHleEZM2d53bq",
"_score": 1,
"_source": {
"appstatusid": 1,
"savingsaccountnumber": "06405110003380",
"allotmentcategory": "Incentive",
"iseligible": null,
"@timestamp": "2018-02-26T14:42:44.882Z",
"applicantfullname": "Demo1",
"pacid": "4432451"
}
},
{
"_index": "applicationstatus",
"_type": "data",
"_id": "WaqQ0mEBHleEZM2d53bq",
"_score": 1,
"_source": {
"appstatusid": 2,
"savingsaccountnumber": "06405110003380",
"allotmentcategory": "Incentive",
"iseligible": null,
"@timestamp": "2018-02-26T14:42:44.882Z",
"applicantfullname": "Demo2",
"pacid": "4432451"
}
}]

Query which i have tried

GET _search/_search?size=0
{
"query" : {
"constant_score" : {
"filter" : {
"range" :
{
"appstatusid" :
{
"from" : 1,
"to" : 100000
}
}
}
}
}
}


(Junaid) #2

You can provide an additional "size":0 parameter in your issued query. In response, you can look at the total field, that contains the count of document matching the criteria.


(Saineshwar Bageri) #3

I have used it _search?size=0 but is there any other way to query and that


(Junaid) #4

You can look at the counts API.

https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-count.html


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.