elasticsearch 嵌套查询不是';查询父项时不使用ElasticSearch,elasticsearch,nest,elasticsearch,Nest" /> elasticsearch 嵌套查询不是';查询父项时不使用ElasticSearch,elasticsearch,nest,elasticsearch,Nest" />

elasticsearch 嵌套查询不是';查询父项时不使用ElasticSearch

elasticsearch 嵌套查询不是';查询父项时不使用ElasticSearch,elasticsearch,nest,elasticsearch,Nest,您好: 我有一个嵌套对象,我正在尝试查询名为FacilityManager的外部对象和内部嵌套对象属性: POST /dev/doc/_search?typed_keys=true { "query":{ "nested":{ "query":{ "bool":{ "must":[ { "term":{

您好:

我有一个嵌套对象,我正在尝试查询名为
FacilityManager
的外部对象和内部嵌套对象属性:

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
会使查询无法工作

id
字段的
术语
查询当前位于
嵌套的
bool
查询中

  • 如果查询应位于
    FacilityManager
    id
    字段,则应以
    FacilityManager
    作为前缀,即
    FacilityManager.id

  • 如果查询位于顶级
    id
    字段上,则它应该是包含
    嵌套的
    查询的
    bool
    查询的一部分,而不是
    嵌套的
    查询的内部