HelloPablo
HelloPablo

Reputation: 625

Filtering across multiple indices using ElasticSearch

Is is possible to write a conditional filter on an Elasticsearch multi-index query?

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?

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.

{
    "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
    }
}

Obviously I'd like to do more in this filter than just exclude items from a certain index, this is simply an example.

Upvotes: 1

Views: 1123

Answers (1)

pkhlop
pkhlop

Reputation: 1844

You should be able to combine several indices query to solve this task.

Upvotes: 3

Related Questions