gpt4 book ai didi

elasticsearch - Elastic Search搜索所有字段并提高精确匹配

转载 作者:行者123 更新时间:2023-12-02 23:07:21 25 4
gpt4 key购买 nike

我是 flex 搜索的新手,我该如何编写查询以在文档的所有字段中搜索关键字(即测试关键字),并提高

  • 在所有字段中均与此关键字词组完全匹配。
  • 某些字段的
  • 出现次数(我将A提升为5,B提升为3,C提升为1)

  • 我在 match_phrase上看到了一些文档,但是它似乎不支持多个字段。
    {
    "query": {
    "multi_match": {
    "query": "test keyword",
    "fields": ["A^5", "B^3", "C^1"]
    }
    }
    }

    最佳答案

    如果您希望所有字段中的关键字词组与boost一起完全匹配,请在下面的搜索查询中尝试使用phrase参数multi-match query进行匹配的搜索查询:
    添加带有索引数据,搜索查询和搜索结果的工作示例
    索引数据:

    {
    "A":"test keyword",
    "B":"a",
    "C":"c"
    }
    {
    "A":"a",
    "B":"test keyword",
    "C":"c"
    }
    {
    "A":"a",
    "B":"b",
    "C":"test keyword"
    }
    搜索查询:
    {
    "query": {
    "bool": {
    "should": [
    {
    "multi_match": {
    "query": "test keyword",
    "fields": [
    "A^5",
    "B^3",
    "C^1"
    ],
    "type":"phrase" <-- note this
    }
    }
    ]
    }
    }
    }
    搜索结果:
    "hits": [
    {
    "_index": "stof_64266554",
    "_type": "_doc",
    "_id": "1",
    "_score": 16.285465,
    "_source": {
    "A": "test keyword",
    "B": "a",
    "C": "c"
    }
    },
    {
    "_index": "stof_64266554",
    "_type": "_doc",
    "_id": "2",
    "_score": 8.142733,
    "_source": {
    "A": "a",
    "B": "test keyword",
    "C": "c"
    }
    },
    {
    "_index": "stof_64266554",
    "_type": "_doc",
    "_id": "3",
    "_score": 1.6285465,
    "_source": {
    "A": "a",
    "B": "b",
    "C": "test keyword"
    }
    }
    ]

    关于elasticsearch - Elastic Search搜索所有字段并提高精确匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64266554/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com