# Elasticsearch multi nested query

**URL:** <https://discuss.elastic.co/t/elasticsearch-multi-nested-query/221505>\
**Category:** Elasticsearch\
**Created:** [February 29, 2020, 4:57am UTC](https://discuss.elastic.co/t/elasticsearch-multi-nested-query/221505 "2020-02-29T04:57:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Onkar\_Kore](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/onkar_kore/32/53413_2.png) [@Onkar\_Kore](https://discuss.elastic.co/u/Onkar_Kore)\
**Post date:** [February 29, 2020, 4:57am UTC](https://discuss.elastic.co/t/elasticsearch-multi-nested-query/221505/1 "2020-02-29T04:57:36Z")

</div>

I have an elastic index with the below mapping. It has an array of vehicle and each array element contains array of info elements.

```auto
PUT test_nested_query
{
  "mappings": {
    "_doc": {
      "properties": {
        "vehicle": {
          "type": "nested",
          "properties": {
            "name": {
              "type": "text"
            },
            "info": {
              "type": "nested",
              "properties": {
                "type": {
                  "type": "text"
                },
                "reported_at": {
                  "type": "date"
                },
                "created_at": {
                  "type": "date"
                }
              }
            }
          }
        }
      }
    }
  }
}

```

Sample documents in the index

```auto
POST test_nested_query/_doc/1
{
  "vehicle": [
    {
      "name": "1",
      "info": [
        {
          "type": "A",
          "reported_at": 1582950792000,
          "created_at": 1582950792000
        }
      ]
    },
    {
      "name": "2",
      "info": [
        {
          "type": "B",
          "created_at": 1582950792000
        }
      ]
    }
  ]
}

POST test_nested_query/_doc/2
{
  "vehicle": [
    {
      "name": "1"
    }
  ]
}

```

I want to search for documents that have `no info present at any level` OR `if info present at any level then resported_at must be present at the same level`.

I am using Elastic Search version 6.5.0.  
I am allowed to modify the mapping at the info level but not at the vehicle level.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 28, 2020, 4:57am UTC](https://discuss.elastic.co/t/elasticsearch-multi-nested-query/221505/2 "2020-03-28T04:57:44Z")

</div>

Closed on March 28, 2020, 4:57am UTC

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