We have a requirement wherein we want to combine two fields into one field during reindex.
For Example:
Original Index:
field1: firstname
field2: lastname
After reindex:
Name: firstname lastname
I have checked some documents on reindex and _update_by_query but I am not able to find my requirement.Can this be done using reindex? or Is there any other way?
I tried using copy_to. I created mappings for the new index and then reindexed the data into the new index but the field is not visible. Since it doesn't create any field, I cannot use it in visualizations.
Can it be done using update_by_query to add a new field which is a concatenated value of two fields?
Have you tried using a script inside the reindex request? I have personally done this many times. You could combine the two fields into one and then use ctx._source.remove("[property name]") to remove the extra field.
Yes, I have tried with sample data.After using reindex and copy_to to create a new field(containing combined value from other two fields ), it will create the new field and you can also use search based on the new field but the new field will not visible in "Discover".
On this example could you provide the mapping of original index and teh mapping of destination index. A good test woul be to set dynamic to strict like that you will see if there is an issue during reindexation.
@Nikhil04 here is a simple example of what I am trying to say. Downside is that the target index will have to create a mapping for the two fields, but you don't have to store them in the document. As I wrote before, the fields can be removed in the reindex script. Here is the example:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.