How to remove many fields by script?

Hi, I'm using script below to remove multiple fields from elasticsearch:
"script" : "ctx._source.remove('new_field1'); ctx._source.remove('new_field2')"
When there are many fields that should be removed, this exception happens:

compile error
illegal_argument_exception
Scripts may be no longer than 16384 characters.

So how can I remove many fields by scripting, without script length overflow?

May create a for loop in painless and pass an array of fields as params?

I'm curious about what you are doing though. Why do you need to remove so many fields?
Wouldn't reindex be better?

How can I use script of removing fields with param of multiple fields?

I never did that. So I don't know. You can in worse case send a param like "1,2,3,4" then split the string in the script on comma and for each Id do whatever you need.

Just an idea.

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