Multiple Indice Search With Filters Applied Per Indice

I want to perform a multiple indice search with a term search for all indices but I want to add filters for a particular indice. For example a term query like:

http://0.0.0.0:9200/index_a,index_b/type1,type2,typ3/_search

{
    "_source": [
        "all my sources"
     ],
    "query": {
        "bool": {
            "filter": [
                [
                    {
                        "query_string": {
                            "fields": [
                                "my fields"
                            ],
                            "fuzziness": 0,
                            "query": "My Search Term For All Indices"
                        }
                    }
                ]
            ]
        }
    },
    "sort": [....],
    "size": 150,
    "aggs": {...}
}

I want to add the following filter query to only be applied to only index_b:

"query": {
        "bool": {
            "filter": [
                [
                    {
                        "query_string": {
                            "default_field": "field_1",
                            "query": "Some OR bool"
                        }
                    },
                    {
                        "query_string": {
                            "default_field": "field_2",
                            "query": "Some OR bool"
                        }
                    },
                    {
                        "query_string": {
                            "default_field": "field_3",
                            "query": "A"
                        }
                    },
                    {
                        "query_string": {
                            "default_field": "field_4",
                            "query": "Some OR bool"
                        }
                    },
                    {
                        "query_string": {
                            "default_field": "field_5",
                            "query": "Blah"
                        }
                    }
                ]
            ]
        }
    }

I don't know how to create the query that I am looking for an would really appreciate any help

Welcome to our community! :smiley:

Have you considered using the _msearch API instead?

My client uses an old version of ES that doesn't support _msearch and upgrading is not an option for them.

_msearch has been available since at least Elasticsearch 0.90 so I doubt that is not a solution.

1 Like

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