搜索不会返回任何结果,尽管我的文档应该与查询匹配。
我确实按https://github.com/elasticsearch/elasticsearch-mapper-attachments安装了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编码的值为" Hello"是" SGVsbG8 =",这是我插入" my_attachment"的值。该文件的领域。
我假设mapper-attachments插件已正确部署,因为我没有在执行上面的映射命令时出错。
非常感谢任何帮助。
答案 0 :(得分: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"
}
}
}
}'