我正在试验ElasticSearch。我在查询嵌套对象时遇到问题。嵌套的查询不按预期工作
我的映射:
curl -X GET http://localhost:9200/testt/resource/_mapping?pretty
{
"resource": {
"properties": {
"bib": {
"type": "nested",
"properties": {
"IssueDate": {
"type": "date",
"format": "dateOptionalTime"
},
"Title": {
"type": "string"
}
}
},
"name": {
"type": "string"
}
}
}
}
我有一个索引资源:
curl -X GET http://localhost:9200/testt/resource/_search?pretty
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "testt",
"_type": "resource",
"_id": "1234",
"_score": 1.0,
"_source": {
"name": "SSS",
"bib": {
"Title": "XSD",
"IssueDate": "2012-12-19"
}
}
}
]
}
}
curl -X GET http://localhost:9200/testt/resource/1234?pretty
{
"_index": "testt",
"_type": "resource",
"_id": "1234",
"_version": 1,
"exists": true,
"_source": {
"name": "SSS",
"bib": {
"Title": "XSD",
"IssueDate": "2012-12-19"
}
}
}
然而,我可以使用查询请求无法找到它:
{
"query": {
"nested": {
"path": "bib",
"query": {
"query_string": {
"query": "XSD"
}
}
}
}
}
搜索:curl -X GET http://localhost:9200/testt/resource/_search?pretty -d '{ "query" : { "nested" : {"path" : "bib", "query" : { "query_string" : {"query" : "XSD"} } } } }'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
我的问题是:我该如何使用嵌套查询找到我的对象?我对嵌套对象bib
的对象感兴趣,它包含字XSD
。对象1234
明确包含XSD
,但我无法找到它。你能告诉我我的查询是否可以吗?它出什么问题了?
我喜欢你的答案。我如何实现'_all'的排除?你可以提供示例查询与排除? –
它不在查询中。它在映射中。你需要指定''include_in_all“:false'。有关更多信息,请参阅http://www.elasticsearch.org/guide/reference/mapping/all-field.html。 – imotov
我可能会使用“s_”前缀。谢谢你的帮助。 –