gpt4 book ai didi

elasticsearch - 如何使用elasticsearch搜索单词的开头?

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

如何设置 flex 搜索,使我可以搜索部分单词或单词开头。

当我运行以下脚本时,除非将其设置为“inte *”,否则它不会找到前缀“inte”。

我无法弄清楚这里出了什么问题!

echo "--- DELETING OLD INDEX ---"

curl -XDELETE 'http://localhost:9200/searchtest?pretty'

echo "--- CREATING INDEX ---"

curl -XPUT 'http://127.0.0.1:9200/searchtest/?pretty=1' -d '{
"mappings" : {
"mytype" : {
"properties" : {
"description": {
"type": "string",
"index_analyzer": "my_analyzer",
"search_analyzer": "standard"
}
}
}
},
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"filter" : [ "standard", "lowercase", "stop" ],
"type" : "custom",
"tokenizer" : "my_tokenizer"
}
},
"tokenizer" : {
"my_tokenizer" : {
"side" : "front",
"max_gram" : 200,
"type" : "edgeNGram"
}
}
}
}
}'

echo "--- INSERTING RECORDS ---"

curl -XPOST 'http://localhost:9200/searchtest/mytype?pretty=1' -d '{
"description": "Programming International!"
}'

curl -XPOST 'http://localhost:9200/searchtest/mytype?pretty=1' -d '{
"description": "i18n is internationalizatin"
}'

echo "--- REFRESH ---"

curl -XPOST 'http://localhost:9200/_refresh?pretty=1'

echo "--- RUNNING QUERY WITH * ---"

curl -XGET 'http://localhost:9200/searchtest/mytype/_search?pretty' -d '
{
"query" : {
"query_string" : {
"query" : "inte*"
}
}
}'

echo "--- RUNNING QUERY ---"

curl -XGET 'http://localhost:9200/searchtest/mytype/_search?pretty' -d '
{
"query" : {
"query_string" : {
"query" : "inte"
}
}
}'

[我使用的是Elasticsearch 0.90.9]

最佳答案

没问题,query_string使用支持通配符的查询解析器,如您所见here

也许您正在寻找匹配以给定前缀开头的术语的前缀查询,请查看此link

curl -XGET 'http://localhost:9200/searchtest/mytype/_search?pretty' -d '
{
"query" : {
"prefix" : {
"description" : {
"value" : "inte"
}
}
}
}'

关于elasticsearch - 如何使用elasticsearch搜索单词的开头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22748898/

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