果核匹配\u短语不返回结果

7kjnsjlb  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(327)

我有以下问题

{
  "from": 0, "size": 10000,
  "query": { "match_phrase": {"Practitioner.DoctorList": "peter goh"} },
}

它不会返回任何结果。
但以下是:

{
  "from": 0, "size": 10000,
  "query": { "match": {"Practitioner.DoctorList": "peter goh"} },
}

返回包含“peter goh”、“peter”和“goh”的内容。
为什么不呢 match_phrase 还什么?因为我只希望结果与“吴彼得”匹配。

7jmck4yq

7jmck4yq1#

由于您没有添加任何示例数据和索引Map,因此 Practitioner 属于 nested 类型)
请参阅匹配短语查询,以获取详细信息
添加索引数据、Map和搜索查询的工作示例。
索引Map:

{
  "mappings": {
    "properties": {
      "Practitioner": {
        "type": "nested" 
      }
    }
  }
}

索引数据:

{
    "Practitioner": [
        {
            "DoctorList": "goh"
        },
        {
            "DoctorList": "peter goh"
        },
        {
            "DoctorList": "peter"
        }
    ]
}

搜索查询:

{
  "query": {
    "nested": {
      "path": "Practitioner",
      "query": {
        "match_phrase": {
          "Practitioner.DoctorList": "peter goh"
        }
      },
      "inner_hits":{}
    }
  }
}

搜索结果:

"hits": [
                {
                  "_index": "fd_cb3",
                  "_type": "_doc",
                  "_id": "1",
                  "_nested": {
                    "field": "Practitioner",
                    "offset": 1
                  },
                  "_score": 0.78038335,
                  "_source": {
                    "DoctorList": "peter goh"
                  }
                }
              ]

相关问题