Painless: Generating a scripted field thats an exact copy of another field

Hi

I'm trying to generate a scripted field that returns only certain tokens of a derived field. For example, if I have a field with possible combination of tokens "Movies, pg13, Drama, comedy, etc" I want to generate a scripted field that only returns the genre tokens (drama, comedy, etc), not the other tokens (pg13, movies, etc). My code to do so is the following:

String r = "";
if (doc['Industry.keyword'].value =~ /drama/) {
r = r + "drama ";
}
if (doc['Industry.keyword'].value =~ /comedy/) {
r = r + "comedy ";
}
return r

This resulted in a "Courier Fetch: 1 of 5 shards failed."

So, I tried simply just writing a script for a field that would return an exact copy of another field. My script is the following:

return doc['Industry.keyword'].value

But it only returns the first token delimited by a comma. So, if a record has the Industry value "Drama, Thriller, Horror," it only returns "Drama." I want it to return the whole string. Any help?

Could you share your mapping for that field as well as a couple of examples of the values inside the field?

Sure thing!

Mapping for the industry field:

"Industry" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}

example values inside the field:

Oh, have you tried using doc['industry'].value instead? That should give you what you want.

Sorry, I meant to put doc['Industry.keyword'].value in my op. Edited op with correction.

Just doc['Industry'].value still gives "Courier Fetch: 1 of 5 shards failed."

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