我正在試驗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_」前綴。謝謝你的幫助。 –