【发布时间】:2015-07-01 12:37:37
【问题描述】:
我正在使用 elasticsearch 短语前缀查询来进行一些自动完成。 它通常工作得很好,但有时找不到不完整的单词,尽管多一个或少一个字母它确实可以找到它。
例如:通过查询“Anomal”和查询“Anomalie”,它确实找到了包含“Anomalie”的内容,但在“Anomali”中找不到任何内容。这对于用户体验来说真的很奇怪!
我之前的谷歌搜索让我尝试禁用停用词,但这并没有解决我的问题。我尝试在分析器中使用停用词配置并作为过滤器。
复制:
索引创建、配置和添加文档:
curl -XPUT 'http://localhost:9200/elastictests/' -d '{
"settings" : {
"index" : {
"analysis" : {
"filter" : {
"french_stemmer" : {
"type" : "stemmer",
"name" : "light_french"
},
"no_stop" : {
"type" : "stop",
"stopwords" : "_none_"
}
},
"analyzer" : {
"default" : {
"type" : "custom",
"stopwords" : "_none_",
"filter" : [ "standard", "lowercase", "asciifolding", "word_delimiter", "french_stemmer", "no_stop" ],
"tokenizer" : "standard"
}
}
}
}
}
}'
curl -XPUT 'http://localhost:9200/elastictests/test/1' -d '{
"title": "Anomalie"
}'
这些查询找到了文档:
curl -XGET 'http://localhost:9200/elastictests/_search?pretty=1' -d '
{
"query" : {
"match" : {
"title" : "Anomalie"
}
}
}
}
'
curl -XGET 'http://localhost:9200/elastictests/_search?pretty=1' -d '
{
"query" : {
"match" : {
"title" : {
"query": "Anomalie",
"type": "phrase_prefix"
}
}
}
}
'
curl -XGET 'http://localhost:9200/elastictests/_search?pretty=1' -d '
{
"query" : {
"match" : {
"title" : {
"query": "Anomal",
"type": "phrase_prefix"
}
}
}
}
'
但是这个没有找到文件,也没有错误:
curl -XGET 'http://localhost:9200/elastictests/_search?pretty=1' -d '
{
"query" : {
"match" : {
"title" : {
"query": "Anomali",
"type": "phrase_prefix"
}
}
}
}
'
知道为什么吗?
【问题讨论】: