gpt4 book ai didi

elasticsearch - Elasticsearch “match_phrase”查询和 “fuzzy”查询-可以结合使用

转载 作者:行者123 更新时间:2023-12-03 01:34:25 25 4
gpt4 key购买 nike

我需要使用match_phrase和模糊匹配的查询。但是我找不到任何文档来构造这样的查询。另外,当我尝试合并查询(一个在另一个)时,它会引发错误。是否可以构造这样的查询?

最佳答案

您将需要使用Span Queries

以下查询将针对champions league执行词组匹配+模糊查询,例如在name类型的示例字段text

如果需要多个字段,请添加另一个must子句。

注意,我提到了slop:0in_order:true,它们可以进行精确的词组匹配,而您可以在fuzzy查询中使用match查询实现模糊行为。

样本文件

POST span-index/mydocs/1
{
"name": "chmpions leage"
}

POST span-index/mydocs/2
{
"name": "champions league"
}

POST span-index/mydocs/3
{
"name": "chompions leugue"
}

跨度查询:
POST span-index/_search
{
"query":{
"bool":{
"must":[
{
"span_near":{
"clauses":[
{
"span_multi":{
"match":{
"fuzzy":{
"testField":"champions"
}
}
}
},
{
"span_multi":{
"match":{
"fuzzy":{
"testField":"league"
}
}
}
}
],
"slop":0,
"in_order":true
}
}
]
}
}
}

响应:
{
"took": 19,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.5753642,
"hits": [
{
"_index": "span-index",
"_type": "mydocs",
"_id": "2",
"_score": 0.5753642,
"_source": {
"name": "champions league"
}
},
{
"_index": "span-index",
"_type": "mydocs",
"_id": "1",
"_score": 0.5753642,
"_source": {
"name": "chmpions leage"
}
},
{
"_index": "span-index",
"_type": "mydocs",
"_id": "3",
"_score": 0.5753642,
"_source": {
"name": "chompions leugue"
}
}
]
}
}

让我知道这是否有帮助!

关于elasticsearch - Elasticsearch “match_phrase”查询和 “fuzzy”查询-可以结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53541053/

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