使用 multi_match AND bool 的 ElasticSearch

ElasticSearch with multi_match AND bool

我尝试学习 Elasticsearch 以将其添加到我的 Rails 应用程序中。 我想对 2 个字段执行 multi_match 查询(就像它们只是一个字段一样),并且还对必须等于 1 的另一个字段(状态)进行筛选。

let response = Wine.search({
  query: {
    multi_match: {
      query: "test",
      fields: ["winery", "name"]
    },
    bool: {
      must: {
        term: { status: 1 }
      },
      should: [],
      minimum_should_match: 1
    }
  }     
})

错误是:

"fields\":[\"winery\",\"name\"]},\"bool\":{\"must\":{\"term\":{\"status\":1}},\"should\":[],\"minimum_should_match\":1}}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT \"bool\"]; }]","status":400}

请求有什么问题?如何同时执行 multi_match 和 BOOL?

使用 filtered query:

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

Elasticsearch 5 的相同查询:

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