弹性搜索bool查询

时间:2017-02-15 21:28:22

标签: elasticsearch

我的理解是在bool查询中,must子句中的所有查询都必须匹配。

但在这种情况下查询

{
"query" : {
    "bool" : {
        "must" : [{
                "multi_match" : {
                    "query" : "Aaron",
                    "fields" : ["first_name"],
                    "fuzziness" : 0
                }
            }, {
                "multi_match" : {
                    "query" : "Brown",
                    "fields" : ["last_name"],
                    "fuzziness" : 0
                }
            }
        ],
        "must_not" : {
            "term" : {
                "id" : "demo12949"
            }
        }
    }
}

返回

    {
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 11,
    "max_score": 6.8716674,
    "hits": [
      {
        "_index": "spicecrmcontacts",
        "_type": "Contacts",
        "_id": "demo24214",
        "_score": 6.8716674,
        "_source": {
          "first_name": "Aaron",
          "full_name": "Aaron Brown",
          "last_name": "Brown",
          "primary_address_country": "US",
          "phone_work": "914-556-8929",
          "created_by_name": "Administrator",
          "assigned_user_name": "Administrator",
          "name": "Aaron Brown",
          "related_ids": [
            null,
            "1"
          ],
          "id": "demo24214",
          "assigned_user_id": "1",
          "date_modified": "2015-09-28 16:40:00",
          "summary_text": "Aaron Brown"
        }
      },
      {
        "_index": "spicecrmcontacts",
        "_type": "Contacts",
        "_id": "demo43309",
        "_score": 2.9901109,
        "_source": {
          "first_name": "Sharon",
          "full_name": "Sharon Brown",
          "last_name": "Brown",
          "primary_address_country": "US",
          "phone_work": "224-772-9602",
          "created_by_name": "Administrator",
          "assigned_user_name": "Administrator",
          "name": "Sharon Brown",
          "related_ids": [
            null,
            "1"
          ],
          "id": "demo43309",
          "assigned_user_id": "1",
          "date_modified": "2015-10-06 12:22:00",
          "summary_text": "Sharon Brown"
        }
      },

因此,如果所有MUST标准都被视为AND,那么为什么Sharon Brown的记录会返回。还有更多这样的东西。我接受布朗的比赛,但亚伦不应该与沙龙相提并论。

任何人都可以了解如何进行查询,以便MUST中的所有部分都与AND结合?

0 个答案:

没有答案