How to get count of returned data in match query?

GET index/_search
{
"query": {"terms": {
"id": [ "114383" ]
}}
get the count of this matched data
}

and also get the count of this

GET products/_search
{
"query": {
"match" : {
"inStorage": "true"
}
}
//get count of this data
}

  1. Using search method as your code and extract count from field['hits']['total'] in response.
  2. Using count method directly, which would return the count of your matched documents.
    The count method is more faster if you only care the count of matched data because count method does not need to fetch result and rank by score. Another, setting the search size to 0 in search method can also decrease the overhead of fetching and scoring, which is similar to count method.

GET /products/_count
{
"query": {
"bool": {
"filter": [
{
"terms": {
"categories.id": ["9"]
}
},
{
"terms": {
"manufacturers.id": ["216"]
}
},
{
"terms": {
"options.id": ["845"]
}
},
{
"term": {
"inStorage.": "true"
}
}
]
}
}
}
thank you but is it possible to filter terms with term?

yes.

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