Update field inside nested type in elasticsearch from java

117 Views Asked by At

Please find the below mapping, We are trying to updated the domains field inside the domains type.

 "mappings":{  
   "candidate":{  
      "_all":{  
         "enabled":false
      },
      "properties":{  
         "domains":{  
            "properties":{  
               "country":{  
                  "type":"short",
                  "include_in_all":false
               },
               "domains":{  
                  "type":"string",
                  "copy_to":[  
                     "domain_exact",
                     "domain_partial"
                  ]
               }
            }
         }
      }
   }
}

And the java code given below,

esMgr.updateIndex(indexName, "candidate", domainDetails[2]).setDoc("domains.domains", domainDetails[1])
                                .get();

We are getting the below exception,

Caused by: MapperParsingException[Field name [domains.domains] cannot contain '.'] 

Can anyone help us on how to fix this issue in java.

1

There are 1 best solutions below

0
On

To update, you can try:

UpdateRequestBuilder br = client.prepareUpdate(indexName, "candidate", domainDetails[2]);
br.setDoc("{\"domains\":{ \"domains\": " + domainDetails[1] + "}}".getBytes());
br.execute();