Search不返回任何结果,尽管我确实有一个与查询匹配的文档。
我确实在每个https://github.com/elasticsearch/elasticsearch-mapper-attachments上安装了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" : [ ]
}
}注意,"Hello“的base64编码值是"SGVsbG8=",这是我插入到文档的"my_attachment”字段中的值。
我假设映射器附件插件已经正确部署,因为执行上面的映射命令时没有出现错误。
任何帮助都将不胜感激。
发布于 2014-11-05 09:07:10
哪个分析器是针对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"
}
}
}
}'https://stackoverflow.com/questions/26742003
复制相似问题