2014-03-30 112 views
0

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

回答

2

沒有什麼錯,在QUERY_STRING使用支持通配符查詢分析器,你可以看到here

也許你正在尋找一個前綴查詢,匹配開始以給定前綴而言這,看看這個link

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

下面建議的比通配符查詢更具擴展性。 – Nate

0

我認爲你正在尋找通配符查詢...

curl -XPOST "http://_search" -d' 
{ 
"query": { 
    "wildcard": { 
     "description": { 
      "value": "inte*" 
         } 
       } 
     } 
}' 

嘗試使用通配符和正則表達式查詢以上查詢..!

HOpe它幫助..!

相關問題