![](/img/trans.png)
[英]How to search a elasticsearch index by partial text of a field in the indexed document?
[英]Unable to search attachment type field in an ElasticSearch indexed document
搜索没有返回任何结果,尽管我有一个应与查询匹配的文档。
我确实每个https://github.com/elasticsearch/elasticsearch-mapper-attachments安装了ElasticSearch映射器附件插件。 我也用谷歌搜索了该主题,并在堆栈溢出中浏览了类似的问题,但没有找到答案。
这是我在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”字段中的值。
我假设已正确部署了mapper-attachments插件,因为在执行上述映射命令时没有出现错误。
任何帮助将不胜感激。
哪个分析器针对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"
}
}
}
}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.