如何设置一个弹性搜索,使我可以搜索单词的一部分或单词的开头。如何用elasticsearch搜索单词的开头?
当我运行下面的脚本时,除非使它成为'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]
下面建议的比通配符查询更具扩展性。 – Nate