gpt4 book ai didi

Elasticsearch query_string 完全匹配

转载 作者:行者123 更新时间:2023-11-29 02:49:39 25 4
gpt4 key购买 nike

我有一个包含 field 视频的索引,其值为 1.flv。如果我执行以下查询:

"query": {
"query_string": {
"query": "2.flv"
}
}

查询仍然返回所有带有 1.flv 的记录。

谁能指出我正确的解决方案?

这是为 1.flv 返回的示例数据(如您所见,没有任何内容包含 2.flv!)

  "hits" : {
"total" : 8,
"max_score" : 0.625,
"hits" : [ {
"_index" : "videos",
"_type" : "comment",
"_id" : "_meta",
"_score" : 0.625,
"fields" : {
"video" : "1.flv",
"body" : "Really?"
}
}, {
"_index" : "videos",
"_type" : "comment",
"_id" : "0fYsYOTHT7O-7P6CVi7l3w",
"_score" : 0.625,
"fields" : {
"video" : "1.flv",
"body" : "fadsfasfas"
}
}, {
"_index" : "videos",
"_type" : "comment",
"_id" : "O9VjgFdmQra6hYxwMdGuTg",
"_score" : 0.48553526,
"fields" : {
"video" : "1.flv",
"body" : "Search is hard. Search should be easy."
}
}, {
"_index" : "videos",
"_type" : "comment",
"_id" : "A6k3FEKKSzKTSAVIT-4EbA",
"_score" : 0.48553526,
"fields" : {
"video" : "1.flv",
"body" : "Really?"
}
}, {
"_index" : "videos",
"_type" : "comment",
"_id" : "eFnnM4PrTSyW6wfxHWdE8A",
"_score" : 0.48553526,
"fields" : {
"video" : "1.flv",
"body" : "Hello!"
}
}, {
"_index" : "videos",
"_type" : "comment",
"_id" : "ZogAiyanQy6ddXA3o7tivg",
"_score" : 0.48553526,
"fields" : {
"video" : "1.flv",
"body" : "dcxvxc"
}
}, {
"_index" : "videos",
"_type" : "comment",
"_id" : "O0HcT7aGTrqKQxF25KsOwQ",
"_score" : 0.37158427,
"fields" : {
"video" : "1.flv",
"body" : "Hello!"
}
}, {
"_index" : "videos",
"_type" : "comment",
"_id" : "l2d53OFITb-etooWEAI0_w",
"_score" : 0.37158427,
"fields" : {
"video" : "1.flv",
"body" : "dasdas"
}
} ]
}
}

最佳答案

您看到的是标准分词器(默认/标准分析器的一部分)的结果,它对句点字符 (.) 进行分词。参见 this play有关如何分析它的快速示例。

有很多方法可以用 Elasticsearch 完成您想要的,例如更新映射和将 video 字段的分析器更改为例如 keyword 分析器,如上所述,可能使用多字段类型,将字段映射配置为 index: not_analyzed 等,但是一个可能对您足够有效的简单解决方案是确保 AND正在使用运算符。

默认情况下,query string query使用 OR 运算符:

default_operator: The default operator used if no explicit operator is specified. For example, with a default operator of OR, the query capital of Hungary is translated to capital OR of OR Hungary, and with default operator of AND, the same query is translated to capital AND of AND Hungary. The default value is OR.

因此,要么明确说明运算符,要么将其设置为默认值。 This play还显示了这两种技术的实际应用(右下 Pane 中的搜索 #1 和搜索 #2 选项卡)。

关于Elasticsearch query_string 完全匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20447087/

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