美好的一天:
我有一个嵌套对象,我正在尝试查询称为facilityManagements
的外部对象和内部嵌套对象属性:
POST /dev/doc/_search?typed_keys=true
{
"query":{
"nested":{
"query":{
"bool":{
"must":[
{
"term":{
"facilityManagements.userId":{
"value":"ad73ef37-243b-400f-b68f-679fa9116769"
}
}
},
{
"term":{
"id":{
"value":"ed08d01c-c791-46de-b3f7-2ab7e1f8823d"
}
}
}
]
}
},
"path":"facilityManagements",
"inner_hits":{
"name":"facilityManagement",
"size":1
}
}
}
}
这将返回一个空响应。但是,当我执行match_all
时,它确实会返回文档:
GET dev/doc/_search
{
"query" : {
"match_all": {}
}
}
响应:
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "dev",
"_type": "doc",
"_id": "ed08d01c-c791-46de-b3f7-2ab7e1f8823d",
"_score": 1,
"_routing": "ed08d01c-c791-46de-b3f7-2ab7e1f8823d",
"_source": {
"name": "Facility 123456",
"status": 0,
"registrationDate": "0001-01-01T00:00:00",
"address": "22100 Sunset Hills Rd suite 150*",
"zipCode": "20190",
"city": "Reston",
"state": "Virginia",
"facilityManagements": [
{
"userId": "ad73ef37-243b-400f-b68f-679fa9116769",
"operations": 1,
"isOwner": true,
"isActive": true,
"createdDate": "2018-07-16T07:47:04.1491212Z",
"id": "5520c28c-614e-40ca-8bde-5f84e83d3829"
}
],
"approved": false,
"businessLocation": {
"lat": 37.5536729,
"lon": -122.3506495
},
"suggest": {
"input": [
"Reston",
"Virginia",
"20190",
"Facility",
"123456",
"22100",
"Sunset",
"Hills",
"Rd",
"suite",
"150*"
]
},
"joinField": "parent",
"id": "ed08d01c-c791-46de-b3f7-2ab7e1f8823d"
}
}
]
}
}
此外,当我只有facilityManagements.userId
时,它确实会返回结果,但是包含id
会使查询不起作用。
答案 0 :(得分:1)
term
字段上的id
查询当前在nested
bool
查询中;
id
的{{1}}字段上,则应以facilityManagements
为前缀,即facilityManagements
或
facilityManagements.id
字段中,则它应该是包含id
查询的bool
查询的一部分,而不是nested
的内部查询。