# Different filter on multiple indexes

**URL:** <https://discuss.elastic.co/t/different-filter-on-multiple-indexes/195151>\
**Category:** Elasticsearch\
**Created:** [August 14, 2019, 7:19am UTC](https://discuss.elastic.co/t/different-filter-on-multiple-indexes/195151 "2019-08-14T07:19:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_T](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_t/32/52248_2.png) [@David\_T](https://discuss.elastic.co/u/David_T)\
**Post date:** [August 14, 2019, 7:19am UTC](https://discuss.elastic.co/t/different-filter-on-multiple-indexes/195151/1 "2019-08-14T07:19:18Z")

</div>

Hello everyone, i have a question about multi indexes search.  
I want search multi indexes and sort by score, now i use \_msearch query, like this

```
get _msearch
{"index" : "user"}
{"query" : {"match" : {"global" : "keyword"}}}
{"index" : "index2"}
{"query" : {"bool" : {"must" : [{"term" : {"field" : {"value" : "value"}}}, {"match" : {"global" : 
"keyword"}}]}}}

```

but this will back two array, how can i search on multi indexes and get back one array, Beacuse i want sort by score and limit top five result.

Please help me , thx.

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 14, 2019, 12:22pm UTC](https://discuss.elastic.co/t/different-filter-on-multiple-indexes/195151/2 "2019-08-14T12:22:25Z")

</div>

Scores from data in separate indexes may not necessarily be comparable, so it may not make sense to sort that data in a single list. One index may very well dominate the top hits, if the scores from that index are higher.

Having said that, you can query the `_index` field. You can use that to query each of the indexes with a single bool query. That would look something like this:

```auto
GET _search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "filter": {
              "term": {
                "_index": "user"
              }
            },
            "must": [
              {
                "match": {
                  "global": "keyword"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "filter": {
              "term": {
                "_index": "index2"
              }
            },
            "must": [
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "field": {
                          "value": "value"
                        }
                      }
                    },
                    {
                      "match": {
                        "global": "keyword"
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![David\_T](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_t/32/52248_2.png) [@David\_T](https://discuss.elastic.co/u/David_T)\
**Post date:** [August 15, 2019, 5:13am UTC](https://discuss.elastic.co/t/different-filter-on-multiple-indexes/195151/3 "2019-08-15T05:13:49Z")

</div>

thanks, It solved my problem.

---

<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:** [September 12, 2019, 5:24am UTC](https://discuss.elastic.co/t/different-filter-on-multiple-indexes/195151/4 "2019-09-12T05:24:22Z")

</div>

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