一尘不染

带有multi_match AND bool的ElasticSearch

elasticsearch

我尝试学习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?


阅读 498

收藏
2020-06-22

共1个答案

一尘不染

使用过滤查询

{
    "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"
                }
            }
        }
    }
}
2020-06-22