No field found for [path] in mapping with types [doc]

My ES document model is as follows

       "hits": [
          {
             "_source": {
                "variant_group": {
                   "variant_info": [
                      {
                         "name": "Toothpaste",
                         "inventory": 10
                      }
                   ],
                   "type_id": 1365
                }
             },
     ]

when I try to execute this query in sorting:

         {
     "_script": {
        "type": "number",
        "order": "desc",
        "script": {
           "lang": "groovy",
           "inline": "return doc['variant_group.variant_info'].values.any{ it -> it.inventory > 0 }"
        }
     }
  }

following error is raised
No field found for [variant_group.variant_info] in mapping with types [merchant_variant_group]

I tried using containsKey as follows:

 {
 "_script": {
"type": "number",
"order": "desc",
"script": {
   "lang": "groovy",
   "inline": "return doc.containsKey('variant_group.variant_info') ? 1 : 0"
}
 }
  }

this script block returns 0 and not 1

However, if I execute this:

 {
 "_script": {
"type": "number",
"order": "desc",
"script": {
   "lang": "groovy",
   "inline": "return doc.containsKey('variant_group.type_id') ? 1 : 0"
}
 }
  }

it returns the expected response 1

Is there a gotcha that I'm missing for collection types or is there some issue with my code?

Thanks!

1 Like

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