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

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.

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.

thank you @thiago

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