Search不会返回任何结果,尽管我有一个应该与查询匹配的文档。
我确实安装了ElasticSearch映射器附件插件https://github.com/elasticsearch/elasticsearch-mapper-attachments.我也在谷歌上搜索过这个话题,也浏览过堆栈溢出中的类似问题,但没有找到答案。
以下是我在Windows7命令提示符中键入的内容:
c:Javaelasticsearch-1.3.4>curl -XDELETE localhost:9200/tce
{"acknowledged":true}
c:Javaelasticsearch-1.3.4>curl -XPUT localhost:9200/tce
{"acknowledged":true}
c:Javaelasticsearch-1.3.4>curl -XPUT localhost:9200/tce/contact/_mapping -d{"
contact":{"properties":{"my_attachment":{"type":"attachment"}}}}
{"acknowledged":true}
c:Javaelasticsearch-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:Javaelasticsearch-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:Javaelasticsearch-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"字段中的值。
我假设mapper附件插件已经正确部署,因为我在执行上面的映射命令时没有遇到错误。
如有任何帮助,我们将不胜感激。
哪个分析器正在针对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"
}
}
}
}'