How to combine multiple bool queries in elasticsearch

后端 未结 1 971
暖寄归人
暖寄归人 2020-12-28 09:40

I want to create the equivalent of the following query -

(city = \'New York\' AND state = \'NY\') AND ((businessName=\'Java\' and businessName=\'Shop\') OR (         


        
相关标签:
1条回答
  • 2020-12-28 10:23

    How about something like this:

    {
        "query": {
            "match_all": {}
        },
        "filter": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "city": "New york"
                        }
                    },
                    {
                        "term": {
                            "state": "NY"
                        }
                    },
                    {
                        "bool": {
                            "should": [
                                {
                                    "bool": {
                                        "must": [
                                            {
                                                "term": {
                                                    "businessName": "Java"
                                                }
                                            },
                                            {
                                                "term": {
                                                    "businessName": "Shop"
                                                }
                                            }
                                        ]
                                    }
                                },
                                {
                                    "bool": {
                                        "must": [
                                            {
                                                "term": {
                                                    "category": "Java"
                                                }
                                            },
                                            {
                                                "term": {
                                                    "category": "Shop"
                                                }
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题