我是ElasticSearch的新手,目前正在探索它的特性。其中之一是我感兴趣的模糊查询,我正在测试,并有麻烦使用。这可能是一个虚拟的问题,所以我想已经使用过这个功能的人会很快找到答案,至少我希望如此。:)
顺便说一句,我觉得它可能不仅与ElasticSearch有关,而且可能直接与Lucene有关。
让我们从一个名为“第一个索引”的新索引开始,在这个索引中,我存储一个带有“美式足球”值的对象“标签”。这是我使用的查询。
bash-3.2$ curl -XPOST 'http://localhost:9200/firstindex/node/?pretty=true' -d '{
"node" : {
"label" : "american football"
}
}
'这就是我得到的结果。
{
"ok" : true,
"_index" : "firstindex",
"_type" : "node",
"_id" : "6TXNrLSESYepXPpFWjpl1A",
"_version" : 1
}到目前为止,我想使用模糊查询找到这个条目。这是我寄来的:
bash-3.2$ curl -XGET 'http://localhost:9200/firstindex/node/_search?pretty=true' -d '{
"query" : {
"fuzzy" : {
"label" : {
"value" : "american football",
"boost" : 1.0,
"min_similarity" : 0.0,
"prefix_length" : 0
}
}
}
}
'这就是我得到的结果
{
"took" : 15,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}如你所见,没有命中。但现在,当我将查询的值从“美式足球”(american)缩小到“美式足球”(american from )时,如下所示:
bash-3.2$ curl -XGET 'http://localhost:9200/firstindex/node/_search?pretty=true' -d ' {
"query" : {
"fuzzy" : {
"label" : {
"value" : "american footb",
"boost" : 1.0,
"min_similarity" : 0.0,
"prefix_length" : 0
}
}
}
}
'然后,我得到了正确的击中我的条目,因此结果是:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.19178301,
"hits" : [ {
"_index" : "firstindex",
"_type" : "node",
"_id" : "6TXNrLSESYepXPpFWjpl1A",
"_score" : 0.19178301, "_source" : {
"node" : {
"label" : "american football"
}
}
} ]
}
}因此,我有几个与这个测试相关的问题:
发布于 2012-04-28 02:16:37
1.
模糊查询根据条件进行操作。它不能处理短语,因为它不分析文本。所以,在你的例子中,elasticsearch试图将“美式足球”与“美式足球”和“足球”相匹配。术语之间的匹配是基于Levenshtein距离的,它用于计算相似分数。由于您有min_similarity=0.0,所以只要编辑距离小于最小项的大小,任何术语都应该与任何术语匹配。在你的例子中,“美式足球”有17码,“美国人”有8码。这两个术语之间的距离是9,比最小的第8项的距离还要大。因此,这个词被拒绝了。“美式足球”和“美国人”之间的编辑距离是6,基本上是“美式”一词,末尾加了6个。这就是它产生结果的原因。对于min_similarity=0.0,任何编辑距离7或更短的内容都会匹配。例如,搜索"aqqqqqq“时甚至会得到结果。
2.
是的,正如我前面所解释的,它与多个单词的值有一定的关系.如果要搜索多个项,请查看像这个查询一样模糊和文本查询的模糊参数。
4和5。
通常,仅次于elasticsearch.org的下一个最佳信息源是elasticsearch源代码。
https://stackoverflow.com/questions/10309199
复制相似问题