Using _update_by_query and painless script with hashmap to update based on value

I have a huge list of keys and values such as this

[{'appid':12345,'lob': 'Finance'},
{'appid':67891,'lob': 'Banking'},
{'appid':11111,'lob': 'Finance'},
{'appid':22222,'lob': 'Fast Food'}]

I want to create a script and the update_by_query to do this

Search all documents where the field AppId (document field value) = appid (from hashmap) and then update the LOB field in the document based on that value.

I'm having a hard time figuring out where to start but I think this is possible.

Thanks in advance.

Hey,

in order to properly find the correct documents, you need to have that array of data indexed as a nested type. Otherwise you would need search all documents and check in your script if there is a single element, that has appId=Foo and lob=Bar.

Can you explain where you are having problems? Is it coming up with the painless script? If so, which part of it exactly? the part of checking if you need to do a replacing or the replacing itself?

--Alex

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