cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Conditionally Remove or Add a Field

Ish
New Contributor III

Hello,

How do you conditionally remove (or add) a field to a document?

E.g., I have a mapper:

Expression โ†’ Target Path
20 โ†’ $field1
10 โ†’ $field2
โ€˜โ€™ โ†’ $field3
null โ†’ $field4

So I now have:
[
{
โ€˜field1โ€™:20
,โ€˜field2โ€™:10
,โ€˜field3โ€™:โ€˜โ€™
,โ€˜field4โ€™:null
}
]

Now for example in pseudo code:

if ( $field2 > 5 ) { delete($.field2) }
if ( $field3 == โ€˜โ€™) {delete($.field3) }
if ( $field4 == null ) { delete($.field4) }

So now it looks like:

[
{
โ€˜field1โ€™:20
}
]

How can I do that? Note: I can achieve this with a JSON Generator using Apache Velocity, but Iโ€™m hoping there is a way to do this using something like a Mapper.

It would also be OK to do this in the opposite direction, e.g.,

if ( $input <= 4 ) { create($.field2, $input) }

Let me know if you have any questions,
Thanks!
Ish

5 REPLIES 5

Sorry, Aha is a mystery to us all. ๐Ÿ™‚ Just reference the ticket in your communications with your CS or support rep.