ElasticSearch with multi_match AND bool

后端 未结 1 1245
陌清茗
陌清茗 2021-01-02 07:39

I try to learn Elasticsearch to add it in my Rails app. I want to perform a multi_match query into 2 fields (as if they were just a single field) and also have a filter to a

相关标签:
1条回答
  • 2021-01-02 07:53

    Use a filtered query:

    {
        "query": {
            "filtered": {
                "query": {
                    "multi_match": {
                        "query": "test",
                        "fields": [
                            "winery",
                            "name"
                        ]
                    }
                },
                "filter": {
                    "term": {
                        "status": "1"
                    }
                }
            }
        }
    }
    

    Same query for Elasticsearch 5:

    {
        "query": {
            "bool": {
                "must": {
                    "multi_match": {
                        "query": "test",
                        "fields": [
                            "winery",
                            "name"
                        ]
                    }
                },
                "filter": {
                    "term": {
                        "status": "1"
                    }
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题