# Multi Index Search - Multiple Queries within the query

**URL:** <https://discuss.elastic.co/t/multi-index-search-multiple-queries-within-the-query/119564>\
**Category:** Elasticsearch\
**Created:** [February 13, 2018, 1:02am UTC](https://discuss.elastic.co/t/multi-index-search-multiple-queries-within-the-query/119564 "2018-02-13T01:02:09Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 13, 2018, 1:22am UTC](https://discuss.elastic.co/t/multi-index-search-multiple-queries-within-the-query/119564/2 "2018-02-13T01:22:39Z")

</div>

You could do this in one query by building a composite query that combines the query that you would wish to execute against a specific index with a `term` or `terms` query that filters only to those indices you're interested in.

As an example, here's a query that executes a search request against all indices, but targets indices `index-1` and `index-2` differently to the rest by using two `bool` queries in the `should` clause of a `bool` query. Each of the inner `bool` queries combines a `must` clause (the query to execute) with a `filter` or `must_not` clause that determines the indices to apply to.

```auto
POST http://localhost:9200/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "query-field": {
                    "value": "query-term"
                  }
                }
              }
            ],
            "filter": [
              {
                "terms": {
                  "_index": [
                    "index-1",
                    "index-2"
                  ]
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "term": {
                  "no-match-query-field": {
                    "value": "no-match-query-term"
                  }
                }
              }
            ],
            "must_not": [
              {
                "terms": {
                  "_index": [
                    "index-1",
                    "index-2"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

---

_[View the full topic](https://discuss.elastic.co/t/multi-index-search-multiple-queries-within-the-query/119564)._
