How to use array variable in regex. Painless scripted field

(dob) #1


How can I use an array value in a regex? Such as:

String returnValue = "";
String[] listarray;
listarray = new String[2];
listarray[0] = "Movies";
listarray[1] = "PG13";

for( int i = 0; i < listarray.size(); i ++ )
if (count =~ /${listarray[i]}/) {
returnValue += listarray;
returnValue += " ";

Many thanks!

(Marius Dragomir) #2


What are you trying to accomplish exactly in that script? There might be a better/easier way to do it.
But from what I can see, this line:
if (count =~ /${listarray[i]}/) should be changed to if (count =~ /listarray[i]/)
and this line:
returnValue += listarray; should probably be returnValue += listarray[i];

(dob) #3


I found an easier way to do it. Do you happen to know how I can use curl to save scripted fields?

(Marius Dragomir) #4

Yes, this is how to add one to Kibana.

saving one is just doing the same and looking for the field name inside the JSON you get from cURL.

(dob) #5

Thanks for the response.
Read the discussion. Since the index-pattern field value is a string and not an array, I cant update it with "source": "ctx._source.tags.add(params.tag)" by adding to the array. So what is the best way to update the field?

Is there a way to simply replace it with something like source": "ctx._source.fields = params.field"

(Marius Dragomir) #6

Wait, are you trying to create more scripted fields from inside a scripted field?

(system) #7

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