Specify an index in search query

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 ?

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

Thanks.

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 with the msearch API as an alternative:

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

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

1 Like

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

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

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