当查询父项时,NEST 查询不适用于 ElasticSearch
NEST query isn't working with ElasticSearch when query parent
美好的一天:
我有一个嵌套对象,我正在尝试查询外部对象和内部嵌套对象 属性 调用 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
}
}
}
}
这 return 是一个空响应。但是,当我执行 match_all
时,它会执行 return 文档:
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
时,它会得到 return 结果,但是包含 id
会使查询无效。
id
字段上的 term
查询当前在 nested
bool
查询中;
- 如果查询应该在
facilityManagements
的 id
字段上,它应该以 facilityManagements
作为前缀,即 facilityManagements.id
或
- 如果查询在顶级
id
字段上,它应该是包含 nested
查询的 bool
查询的一部分,而不是在 [=12] 内部=] 查询.
美好的一天:
我有一个嵌套对象,我正在尝试查询外部对象和内部嵌套对象 属性 调用 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
}
}
}
}
这 return 是一个空响应。但是,当我执行 match_all
时,它会执行 return 文档:
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
时,它会得到 return 结果,但是包含 id
会使查询无效。
id
字段上的 term
查询当前在 nested
bool
查询中;
- 如果查询应该在
facilityManagements
的id
字段上,它应该以facilityManagements
作为前缀,即facilityManagements.id
或
- 如果查询在顶级
id
字段上,它应该是包含nested
查询的bool
查询的一部分,而不是在 [=12] 内部=] 查询.