Enriching data from nested field query

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:

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

Example doc:

{
     "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:

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

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