# Pass indice name in aggregation

**URL:** <https://discuss.elastic.co/t/pass-indice-name-in-aggregation/166392>\
**Category:** Elasticsearch\
**Created:** [January 30, 2019, 4:10pm UTC](https://discuss.elastic.co/t/pass-indice-name-in-aggregation/166392 "2019-01-30T16:10:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pramod.kumar2](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pramod.kumar2](https://discuss.elastic.co/u/pramod.kumar2)\
**Post date:** [January 30, 2019, 4:10pm UTC](https://discuss.elastic.co/t/pass-indice-name-in-aggregation/166392/1 "2019-01-30T16:10:54Z")

</div>

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" } }  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 30, 2019, 4:23pm UTC](https://discuss.elastic.co/t/pass-indice-name-in-aggregation/166392/2 "2019-01-30T16:23:28Z")

</div>

But why not:

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

```

---

<div class="post-metadata">

**Author:** ![Pramod\_Kumar1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pramod_kumar1/32/63905_2.png) [@Pramod\_Kumar1](https://discuss.elastic.co/u/Pramod_Kumar1)\
**Post date:** [January 30, 2019, 9:31pm UTC](https://discuss.elastic.co/t/pass-indice-name-in-aggregation/166392/3 "2019-01-30T21:31:56Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 31, 2019, 1:01pm UTC](https://discuss.elastic.co/t/pass-indice-name-in-aggregation/166392/4 "2019-01-31T13:01:27Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/mapping-index-field.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 28, 2019, 1:08pm UTC](https://discuss.elastic.co/t/pass-indice-name-in-aggregation/166392/5 "2019-02-28T13:08:37Z")

</div>

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