# Enriching data from nested field query

**URL:** <https://discuss.elastic.co/t/enriching-data-from-nested-field-query/280993>\
**Category:** Elasticsearch\
**Created:** [August 11, 2021, 6:39am UTC](https://discuss.elastic.co/t/enriching-data-from-nested-field-query/280993 "2021-08-11T06:39:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amamdouh](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@amamdouh](https://discuss.elastic.co/u/amamdouh)\
**Post date:** [August 11, 2021, 6:39am UTC](https://discuss.elastic.co/t/enriching-data-from-nested-field-query/280993/1 "2021-08-11T06:39:35Z")

</div>

Hi there..,

I'm trying to setup an enrich policy that matches a nested field and then returns the parent object, but couldn't find a way so far..

My index mapping looks like this:

```auto
{
  "lkp_persons": {
      "mappings": {
          "properties": {
               "name": { "type": "text" },
               "locations": {
                     "type": "nested",
                     "properties": {
                              "location_id": { "type": "long" },
                              "location_name": { "type": "text" }
                      }
               }
          }
     }
  }
}

```

Example doc:

```auto
{
     "name": "John",
     "locations": [
              {"location_id": 1, "location_name": "loc_1"},
              {"location_id": 2, "location_name": "loc_2"}
     ]
}

```

Now the enrich policy that I'm trying to setup is like this:

```auto
PUT /_enrich/policy/lkp-persons-policy
{
   "match": {
          "indices": "lkp-persons",
          "match_field": "locations.location_id", //--> the path to the nested matching field
          "enrich_fields": ["name", "locations"]
    }
}

```

The problem is when I try to put this policy I get the following error:  
"Could not traverse mapping to field [locations.location\_id]. The [locations] field must be regular object but was nested.

So how to match with such nested fields any ideas?  
Thanks in advance

> Elasticsearch version: 7.13.4

---

<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:** [September 8, 2021, 6:39am UTC](https://discuss.elastic.co/t/enriching-data-from-nested-field-query/280993/2 "2021-09-08T06:39:51Z")

</div>

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