ElasticSearch:在不同的领域中搜索

xv8emn3q  于 2023-04-29  发布在  ElasticSearch
关注(0)|答案(1)|浏览(130)

我目前正在尝试写一个关于如何处理搜索的ElasticSearch查询。
现在,用我的代码:

{
    "multi_match": {
        "query": {searchTerm},
        "fields": [
            "first_name",
            "last_name"
        ],
        "type": "cross_fields",
        "operator": "and"
    }
}

如果searchTerm是'Example Bazz',则返回'Example Bazz'。但是,如果搜索词是“Example B”,我希望它返回“Example Bar,Example Bazz,Example Boo”。..'
有谁能帮助找出正确的查询,使查询字符串像多个字段的matchPrefix一样充当一个单词吗?

vxqlmq5t

vxqlmq5t1#

我做了这个例子。我猜这句话应该是在田野里您可以合并查询。我保留您的多匹配查询,并添加一个新的多匹配查询类型为“phrase_prefix”。

POST teste/_doc
{
  "first_name":"Example Bar"
}

GET teste/_search
{
  "query": {
    "bool": {
      "minimum_should_match": 1,
      "should": [
        {
          "multi_match": {
            "query": "Example B",
            "fields": [
              "first_name",
              "last_name"
            ],
            "type": "cross_fields",
            "operator": "and"
          }
        },
        {
          "multi_match": {
            "query": "Example B",
            "fields": [
              "first_name",
              "last_name"
            ],
            "type": "phrase_prefix",
            "operator": "and"
          }
        }
      ]
    }
  }
}

相关问题