title: Filtering across multiple indices using ElasticSearch
body: <p>Is is possible to write a conditional filter on an Elasticsearch multi-index query?</p>
  
  <p>I am looking at the filter script, but I can't see anywhere in the documentation if the documents index is a variable I can check?</p>
  
  <p>My existing query looks like this, note the filter script doesn't work - but I assume this is where I need to do my query.</p>
  
  <pre><code>{
      "index": "tweets,articles,animals,buildings",
      "type": "item",
      "body": {
          "query": {
              "multi_match": {
                  "query": "cat",
                  "type": "phrase_prefix",
                  "fields": [
                      "label",
                      "body"
                  ]
              }
          },
          "filter": {
              "script": {
                  "script": "if (_index == \"animals\") {return true;} else {return false}
              }
          },
          "from": 0,
          "size": 8
      }
  }
  </code></pre>
  
  <p>Obviously I'd like to do more in this filter than just exclude items from a certain index, this is simply an example.</p>