如何設置一個彈性搜索,使我可以搜索單詞的一部分或單詞的開頭。如何用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