Elastic search: Nested query with and condition on parent and child


(Nishant Kumar) #1

I have 2 sample record like below:

{
    "parents": [
      {
        "child": [
          {
            "is_deleted": false,
            "child_id": -1,
            "timestamp": 1483536052232
          }
        ],
        "parent_id": 810
      },
      {
        "child": [
          {
            "is_deleted": true,
            "child_id": 105,
            "timestamp": 1483537567000
          }
        ],
        "parent_id": 42
      }
    ]
},
{
  "parents": [
      {
        "child": [
          {
            "is_deleted": false,
            "child_id": 105,
            "timestamp": 1483537567000
          }
        ],
        "parent_id": 42
      }
    ]
}

and my mapping:

"properties": {
  "parents": {
    "type": "nested",
    "properties": {
      "parent_id": {
        "type": "integer",
        "doc_values": false
      },
      "child": {
        "type": "nested",
        "properties": {
          "is_deleted": {
            "type": "boolean",
            "doc_values": false
          },
          "child_id": {
            "type": "integer",
            "doc_values": false
          },
          "timestamp": {
            "type": "long",
            "doc_values": false
          }
        }
      }
    }
  }

I want to search by parent ID which has at least one child with is_deleted as false. For example if i will query with parent ID 42, i should get only 2nd document not first.


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.