我是一名初学者,正在探索 ElasticSearch 的特性。其中我感兴趣的一个是 Fuzzy Query,但我在测试和使用它时遇到了麻烦。这可能是一个傻瓜问题,所以我希望已经使用过这个功能的人能够快速找到答案。
顺便说一下,我有一种感觉,这可能不仅与 ElasticSearch 有关,而且可能直接与 Lucene 有关。
让我们从创建一个名为“first index”的新索引开始,在其中存储一个值为“美式足球”的对象“label”。这是我使用的查询。
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 football"缩小到"american footb"时,就像这样:
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"
}
}
} ]
}
}
关于这个测试,我有几个问题:
为什么使用完全等于我的唯一条目 "american football" 的值执行查询时没有任何结果?
这是否与我具有多个单词的值有关?
是否有一种方法可以在我的查询结果中获取“相似度”分数,以便我更好地了解如何找到模糊查询的正确阈值?
ElasticSearch网站上专门介绍了“模糊查询”的页面,但我不确定它列出了我可以用于模糊查询的所有潜在参数。我应该在哪里找到这样详尽的列表?
其他查询同样的问题。
使用Lucene语法进行模糊匹配的查询字符串查询和模糊查询之间是否有区别?