Skip to content

should nested within must #51

@gitemconte

Description

@gitemconte

I am curious if it is possible with this module to set up a complex elastic query that has should queries nested within a must.

Simply, I am trying to recreate this SQL query:
SELECT * FROM test where status = 'active' and (city = 'New York' or city = 'Toronto')

I would like to get back something similar to the below, but I have only been able to have the MUST and the SHOULD on the same level. Is this functionality possible? It seems like a simple query case, but maybe I am wrong.

{
    "query": {
        "bool": {
            "must": {
                "bool": {
                    "must": [
                        {
                            "match": {
                                "status": {
                                    "query": "active"
                                }
                            }
                        },
                        {
                            "bool": {
                                "should": [
                                    {
                                        "match": {
                                            "city": {
                                                "query": "New York"
                                            }
                                        }
                                    },
                                    {
                                        "match": {
                                            "city": {
                                                "query": "Toronto"
                                            }
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions