# Specify an index in search query

**URL:** <https://discuss.elastic.co/t/specify-an-index-in-search-query/336221>\
**Category:** Elasticsearch\
**Created:** [June 16, 2023, 12:25pm UTC](https://discuss.elastic.co/t/specify-an-index-in-search-query/336221 "2023-06-16T12:25:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephane\_chan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephane_chan/32/122193_2.png) [@stephane\_chan](https://discuss.elastic.co/u/stephane_chan)\
**Post date:** [June 16, 2023, 12:25pm UTC](https://discuss.elastic.co/t/specify-an-index-in-search-query/336221/1 "2023-06-16T12:25:56Z")

</div>

I need to search multiple indexes on Elasticsearch,  
My problem is that on each index I have the same field name (is\_active), how do I specify that it's the field of the other index ?

```auto
GET index-1,index-2/_search
{
	"query":{
		"bool":{
			"must":[
				{"term":{
					"index-1.is_active":true
				}},
				{"term":{
					"index-2.is_active":false
				}},		
			]	
		}
	}
}

```

Thanks.

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 16, 2023, 2:38pm UTC](https://discuss.elastic.co/t/specify-an-index-in-search-query/336221/2 "2023-06-16T14:38:08Z")

</div>

Hi @stephane_chan,

I don't believe you can specify the index as part of a `bool` query in the format you have specified. Have you had a look at using [multisearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html) with the `msearch` API as an alternative:

```auto
GET index-1/_msearch
{ }
{"query" : {"term" : { "is_active": true}}}
{"index": "index-2"}
{"query" : {"term" : { "is_active": false}}}

```

---

<div class="post-metadata">

**Author:** ![stephane\_chan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephane_chan/32/122193_2.png) [@stephane\_chan](https://discuss.elastic.co/u/stephane_chan)\
**Post date:** [June 19, 2023, 5:41am UTC](https://discuss.elastic.co/t/specify-an-index-in-search-query/336221/3 "2023-06-19T05:41:52Z")

</div>

Hi @carly.richmond ,

The solution I found was to rename the fields of each index, like "index-1\_is\_active" and "index-2\_is\_active" . But I haven't yet tested what you've suggested, so I'll take a look at it.

Thanks

---

<div class="post-metadata">

**Author:** ![stephane\_chan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephane_chan/32/122193_2.png) [@stephane\_chan](https://discuss.elastic.co/u/stephane_chan)\
**Post date:** [June 19, 2023, 2:41pm UTC](https://discuss.elastic.co/t/specify-an-index-in-search-query/336221/4 "2023-06-19T14:41:30Z")

</div>

The other solution I've found is to duplicate the field in the index:

```auto
"mappings": {
        "properties": {
            "id":{
                "type": "long"
            },
            "index-1": {
                "properties": {
                    "is_active": {
                        "type": "boolean"
                    }
                }
            },
            "is_active": {
                "type": "boolean"
            }
        }
}

```

---

<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:** [July 17, 2023, 2:42pm UTC](https://discuss.elastic.co/t/specify-an-index-in-search-query/336221/5 "2023-07-17T14:42:02Z")

</div>

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