gpt4 book ai didi

elasticsearch - 在Elasticsearch中使用3的edge-ngram时如何匹配1-2个字符的完全匹配

转载 作者:行者123 更新时间:2023-12-03 01:03:48 28 4
gpt4 key购买 nike

我正在使用Elasticsearch查询具有模糊匹配的索引。我正在使用min_gram长度为3的edge-ngram标记器。

但是,对于仅包含1个或2个字符的查询,此操作不返回任何内容。是否可以仅匹配那些1或2个字符的完全匹配项,但是将edge-ngram用于具有三个或更多字符的查询?

这是我当前的elasticsearch索引映射:

curl -XPUT 'http://localhost:9200/person' -d '{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 3,
"max_gram": 20
}
},
"analyzer": {
"default": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
}'

要查询该索引,请执行以下请求:
curl -XPOST 'localhost:9200/person/type/_search' -d '{
"query": {
"match": {
"_all": "Tim”
}
}
}'

产生大量结果,但是这样的请求
curl -XPOST 'localhost:9200/person/type/_search' -d '{
"query": {
"match": {
"_all": "Ti”
}
}
}'

给出一个空集。理想情况下,如果索引中有某人名为Tim,则第二个请求将返回一些结果。

最佳答案

我不确定这是否可以满足您的所有要求。您可以检查用户输入的长度是否小于3,然后触发以下查询。

{
"query": {
"match_phrase_prefix": {
"_all": "ti"
}
}
}

关于elasticsearch - 在Elasticsearch中使用3的edge-ngram时如何匹配1-2个字符的完全匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33676800/

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