# How we can differentiate the index if the same column name present in multiple indeces (while getting the data from multiple indeces)

**URL:** <https://discuss.elastic.co/t/how-we-can-differentiate-the-index-if-the-same-column-name-present-in-multiple-indeces-while-getting-the-data-from-multiple-indeces/113452>\
**Category:** Elasticsearch\
**Created:** [December 28, 2017, 1:38pm UTC](https://discuss.elastic.co/t/how-we-can-differentiate-the-index-if-the-same-column-name-present-in-multiple-indeces-while-getting-the-data-from-multiple-indeces/113452 "2017-12-28T13:38:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skodari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skodari/32/19875_2.png) [@skodari](https://discuss.elastic.co/u/skodari)\
**Post date:** [December 28, 2017, 1:38pm UTC](https://discuss.elastic.co/t/how-we-can-differentiate-the-index-if-the-same-column-name-present-in-multiple-indeces-while-getting-the-data-from-multiple-indeces/113452/1 "2017-12-28T13:38:28Z")

</div>

Hi Team,  
I need a query to get the data from multiple indexes. here is my question.

If we have two indexes like

1. Index: my\_index1  
fields: sr\_id, exp\_date
2. Index: my\_index2  
fields: sr\_id, s\_name

> GET /my\_index1,my\_index2/\_search  
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "bool":{  
> "must":[  
> {"match":{  
> "sr\_id.keyword": "10011"  
> }  
> }  
> ]}},  
> {  
> "bool": {  
> "must": {  
> "match": {  
> "sr\_id.keyword": "10099"  
> }  
> }  
> }  
> }  
> ]  
> }  
> }  
> }

It is fetching unexpected data from another index of this two indexes. because of the same column name present in this indexes.  
Is there any possibility to pass the index name in bool to get the proper data from expected index.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [January 1, 2018, 6:23pm UTC](https://discuss.elastic.co/t/how-we-can-differentiate-the-index-if-the-same-column-name-present-in-multiple-indeces-while-getting-the-data-from-multiple-indeces/113452/2 "2018-01-01T18:23:19Z")

</div>

Every document has a metadata field, named `_index`, which has the index name that the document belongs to. This is a standard keyword field as any other, so you can combine your query with a Term Query, for instance, on the `_index` field.

---

<div class="post-metadata">

**Author:** ![skodari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skodari/32/19875_2.png) [@skodari](https://discuss.elastic.co/u/skodari)\
**Post date:** [January 2, 2018, 1:44pm UTC](https://discuss.elastic.co/t/how-we-can-differentiate-the-index-if-the-same-column-name-present-in-multiple-indeces-while-getting-the-data-from-multiple-indeces/113452/3 "2018-01-02T13:44:34Z")

</div>

thank you @thiago

---

<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:** [January 30, 2018, 1:44pm UTC](https://discuss.elastic.co/t/how-we-can-differentiate-the-index-if-the-same-column-name-present-in-multiple-indeces-while-getting-the-data-from-multiple-indeces/113452/4 "2018-01-30T13:44:36Z")

</div>

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