2017-01-16 134 views
0

我使用的elasticsearch版本是es2.2。我輸入了與全文搜索官方教程相同的代碼。 (https://www.elastic.co/guide/en/elasticsearch/guide/current/match-query.htmlElasticsearch:全文搜索不起作用

看來全文不適合我。我的設置有什麼問題?謝謝!
我的代碼類型如下:

curl -XDELETE 'localhost:9200/my_index ' 
curl -XPUT 'localhost:9200/my_index ' -d ' 
{ 
"settings": { "number_of_shards": 1 } 
}' 
curl -XPOST 'localhost:9200/my_index/my_type/_bulk' -d' 
{ "index": { "_id": 1 }} 
{ "title": "The quick brown fox" } 
{ "index": { "_id": 2 }} 
{ "title": "The quick brown fox jumps over the lazy dog" } 
{ "index": { "_id": 3 }} 
{ "title": "The quick brown fox jumps over the quick dog" } 
{ "index": { "_id": 4 }} 
{ "title": "Brown fox brown dog" }' 

curl -XGET 'localhost:9200/my_index/my_type/_search' -d' 
{ 
    "query": { 
     "match": { 
      "title": "QUICK!" 
     } 
    } 
}' 

返回的結果爲:{ 「花」:1, 「TIMED_OUT」:假, 「_碎片」:{ 「總」:1, 「成功」:1 ,「失敗」:0},「hits」:{「total」:0,「max_score」:null,「hits」:[]}}

當我輸入精確查詢時,它存儲在索引中。

curl -XGET 'localhost:9200/my_index/my_type/_search' -d' 
{ 
    "query": { 
     "match": { 
      "title": "The quick brown fox" 
     } 
    } 
}' 

輸出是: { 「花」:1, 「TIMED_OUT」:假, 「_碎片」:{ 「總」:1, 「成功」:1, 「失敗」:0}」命中 「:{」 總 「:1,」 MAX_SCORE 「:1.4054651,」 命中 「:[{」 _索引 「:」 my_index」, 「_類型」: 「my_type」, 「_ ID」: 「1」, 「_分數」: 1.4054651, 「_源」:{ 「標題」: 「快速褐色fox」}}]}}

我還測試分析儀:

curl -XGET 'localhost:9200/_analyze' -d' 
{ 
    "analyzer": "standard", 
    "text": "Text to analyze" 
}' 

捲曲:(6)無法解析主機'GET' {「t okens 「:[{」 標記 「:」 文本 「 」start_offset「:0 」end_offset「:4, 」類型「: 」「, 」位置「:0},{ 」標記「: 」到「,」 start_offset 「:5」,end_offset 「:7,」 類型 「:」 「 」位置「:1},{ 」標記「: 」分析「, 」start_offset「:8中, 」end_offset「:15, 」類型「:」 「,」position「:2}]}

這個錯誤是否影響結果?

+0

那麼你執行什麼查詢會導致「錯誤」結果? – rednaw

+0

該查詢顯示在代碼中。它是:curl -XGET'localhost:9200/my_index/my_type/_search'-d' { 「query」:{ 「match」:{ 「title」:「QUICK!」 } } }' – chocolate9624

+0

您是否嘗試搜索「quick」而不是'QUICK!'?另外,最後一次搜索在'curl'命令中有'GET'兩次。 – rednaw

回答

0

現在可以!問題是我沒有爲「標題」索引設置「分析器」。當我設置「分析器」時,全文搜索起作用!我不應該相信默認的分析儀。