Upsert - merge existing attributes/fields

I'm using ES 2.3.1 and I have a use case where there could be more than 1 documents with given ID and we want to merge those documents.

Example:

  • document1 comes with "name:abc"
  • again document1 comes with "name: xyz"
  • Now I want document1 to have: "name: [abc, xyz]" i.e. merged document.

I thought using upsert will solve my problem, but upsert adds new attributes/fields without merging existing/overlapping fields between 2 documents.

How can I achieve what I want with ES ?

Thanks,
..... Amol

Hey,

how about a scripted upsert that allows you to write a script that takes care of merging?

--Alex

Thanks Alexander. Seems script is going to work, but before I do that (enable and try scripts), is there any way to tell ES to merge attributes while calling upsert (i.e. ES would take care of merging instead of we writing a script)?

Thanks,
..... Amol

Hey,

ES cannot really take care of merging, as it is hard to tell what merging means. For one persons it means, all elements of a list should be concatenated together. For someone else it means, that all elements of a list should be concatenated together, but without duplicates. What about deeper inner objects, how should those be merged?

As it is really hard to answer this questions without knowing the application, scripting is there, so you can solve this.

--Alex

Thanks again Alexander.
I tried scripts and it is working well for me. Thanks again for the pointers.

Thanks,
..... Amol

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