2014-11-04 101 views
0

儘管我的文檔應該與查詢匹配,但搜索並不返回任何結果。無法在ElasticSearch索引文檔中搜索附件類型字段

我的ElasticSearch映射器附件插件按照https://github.com/elasticsearch/elasticsearch-mapper-attachments安裝。我也搜索了這個主題,並瀏覽了堆棧溢出中的類似問題,但沒有找到答案。

這是我鍵入到Windows 7的命令提示符:

c:\Java\elasticsearch-1.3.4>curl -XDELETE localhost:9200/tce 
{"acknowledged":true} 

c:\Java\elasticsearch-1.3.4>curl -XPUT localhost:9200/tce 
{"acknowledged":true} 

c:\Java\elasticsearch-1.3.4>curl -XPUT localhost:9200/tce/contact/_mapping -d{\" 
contact\":{\"properties\":{\"my_attachment\":{\"type\":\"attachment\"}}}} 
{"acknowledged":true} 

c:\Java\elasticsearch-1.3.4>curl -XPUT localhost:9200/tce/contact/1 -d{\"my_atta 
chment\":\"SGVsbG8=\"} 
{"_index":"tce","_type":"contact","_id":"1","_version":1,"created":true} 

c:\Java\elasticsearch-1.3.4>curl localhost:9200/tce/contact/_search?pretty 
{ 
    "took" : 2, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 1, 
    "max_score" : 1.0, 
    "hits" : [ { 
     "_index" : "tce", 
     "_type" : "contact", 
     "_id" : "1", 
     "_score" : 1.0, 
     "_source":{"my_attachment":"SGVsbG8="} 
    } ] 
    } 
} 

c:\Java\elasticsearch-1.3.4>curl localhost:9200/tce/contact/_search?pretty -d{\" 
query\":{\"term\":{\"my_attachment\":\"Hello\"}}} 
{ 
    "took" : 1, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 0, 
    "max_score" : null, 
    "hits" : [ ] 
    } 
} 

注意,base64編碼的「你好」是值「SGVsbG8 =」,這是我已經插入到「my_attachment」的價值文件的字段。

我假設mapper-attachments插件已正確部署,因爲我沒有執行上述映射命令時出現錯誤。

任何幫助將不勝感激。

回答

0

my_attachment字段運行什麼分析器?

如果它是標準分析器(看不到任何列出的內容),則文本中的Hello將在索引中變爲小寫。

即做一個字詞的搜索(不具有在其上的分析儀)時 - 嘗試搜索hello

curl localhost:9200/tce/contact/_search?pretty -d' 
    {"query": 
     {"term": 
     {"my_attachment":"hello" 
     }}}' 

你還可以看到哪些條款已經添加到索引:

curl 'http://localhost:9200/tce/contact/_search?pretty=true' -d '{ 
    "query" : { 
     "match_all" : { } 
    }, 
    "script_fields": { 
     "terms" : { 
     "script": "doc[field].values", 
     "params": { 
      "field": "my_attachment" 
     } 
     } 
    } 
}' 
+0

我假設它是默認的分析器原因我沒有做任何配置更改。我也嘗試用「你好」來搜索,但沒有運氣 - 仍然沒有返回任何結果。 – zorbathegeek 2014-11-05 20:02:15

+0

它確實覺得問題出在附件類型字段中。我添加了另一個包含字符串值的兩個屬性的文檔,並對它們執行搜索以返回預期的結果。 curl -XPUT http:// localhost:9200/tce/contact/3 -d'{「 firstName」:「John」,「lastName」:「Doe」}' curl localhost:9200/tce/contact/_search?pretty -d {「query」:{「term」:{「firstName」:「john」}}} 按預期返回一個文檔(響應縮寫): ... 「hits」:{ 「總數「:1, ... 」命中「:[{」012「,」_id「:」3「, 」_score「:0.30685282, 」_source「:{」firstName「:」John「,」lastName「 「Doe」} }] – zorbathegeek 2014-11-05 20:16:23

+0

原來這是插件安裝的問題。刪除以前的安裝並重新安裝。使用上述步驟重新創建索引,並且搜索返回了正確的結果集。無論如何,建議嘗試使用全部小寫關鍵字仍然有幫助。接受答案。謝謝! – zorbathegeek 2014-11-14 00:20:08

相關問題