我今天刚开始研究Elasticsearch,并试图用类似的Elasticsearch查询替换现有的lucene.net实现模糊搜索。
我正在使用Elasticsearch.Net ElasticLowLevelClient
通过docker作为我的服务器运行
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.4.0
我越来越近了,我只是遇到一些问题,无法返回低值(value)的结果。
我希望自己的查询始终返回0分。
例如我有一个文档,其列值为tatra
查询“达”
返回5个结果,但不返回tatra
查询“tatr”
返回tatra结果
var node = new Uri("http://127.0.0.1:9200");
var config = new ConnectionConfiguration(node);
_client = new ElasticLowLevelClient(config);
var searchResponse = await _elasticsearchService._client.SearchAsync<StringResponse>(
indexName,
indexName,
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
PostData.Serializable(new
{
from = 0,
size = maxReturnCount,
min_score = 0.0,
query = new
{
multi_match = new
{
fields = "*",
type = "most_fields",
query = string.Join(" ", queryParts),
fuzziness = "AUTO",
zero_terms_query = "all"
}
}
})
);
我以前在lucene中使用的查询类似于
“达〜”
最佳答案
根据Elasticsearch docs,关于模糊性:AUTO
generates an edit distance based on the length of the term. Low and high distance arguments may be optionally provided AUTO:[low],[high], if not specified, the default values are 3 and 6, equivalent to AUTO:3,6 that make for lengths:
0..2
must match exactly
3..5
one edit allowed
>5
two edits allowed
因此,如果无论词长如何,都允许进行2次编辑,请不要使用自动。使用模糊度= 2。
关于elasticsearch - 如何获得Elasticsearch多匹配模糊搜索以始终返回最少数量的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52289924/