Title is kinda explicative. How do I use a set processor in an ingest pipeline only if another field exists?
I mean, I want to copy the value of field_A into another field_B only if field_A does exist.
Guess it can be accomplished since there's the 'if' parameter among the Set Processor ones, but I do not know the correct syntax to use it.
Thank you so much. It works apparently even though I cannot access nested fields with the same syntax I use in the conditional if of the script processor.
Ok I tested it and both your solutions worked like a charm. Maybe I was working with a wrong input (field containing a dot in its name without being a nested object).
Anyway, I'll share my test (where I included several combinations) so it may help somebody with the syntax:
Just to cover all possibilities, what if I wanted to access a non-nested fields with dots in its name inside the "field" part? Let's suppose I'm in a situation where if a field inner nested in a object outer is present, I want to add an additional field fake.nested.field.
One last nit. No need to hassle with containsKey, just use
"if": "ctx?.outer?.inner == 'Y'"
I would generally not recommend using dots in field names, cause of its ambiguity when specifying inner fields. I think scripting like this could work though
Regardind the fields with dots in the name, I always try not to use them but sometimes they're added by external applications or somebody who does something wrong adds them, so I'd like to learn how to handle them.
I knew I could handle them via script but what if I wanted to remove that field rather than add it?
In that case I'd need a remove processor so I'd fall back on the previous syntax.
Or is there another way to remove a fake nested field (maybe via script as well)?
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.