Pass indice name in aggregation

Hi Team,

I am using elasticsearch 6.2.3. I want to know how we can pass index name in aggregation filtering to get aggregation results for particular index. My search query currently working on multiple indices(Using one aliase name). Below is the sample -

Please help me out in this.

{
"aggs" : {
"t_shirts" : {
"filter" : { "term": { "type": "t-shirt" } }, // here I want to pass index name to filter on this aggs.
"aggs" : {
"avg_price" : { "avg" : { "field" : "price" } }
}
}
}
}

But why not:

GET /index_name/_search
{
  "aggs" : {
    "t_shirts" : {
      "filter" : { "term": { "type": "t-shirt" } },
      "aggs" : {
        "avg_price" : { "avg" : { "field" : "price" } }
      }
    }
  }
}

Hi David,

This will filter all aggregations but I need to filter only one aggregation and if we pass index name with search, then it will filter out query results as well as aggregation data and that's not what I am looking for.

As I know we can pass index name in aggregations using something like indexed filtered aggregation. But how we can do, didn't know. If anyone know, then please share query sample as it will be great helpfull...

Thanks,

I did not check but may be you can have a Term Query on _index field?
See https://www.elastic.co/guide/en/elasticsearch/reference/6.6/mapping-index-field.html

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