How to use scripted field for converting string to int based on condition?

Can someone help me out? I am trying to convert a field I have from a string to an int when a condition is met.

This is what I have so far:

if (doc['burn.keyword'].value == "Yes") {
return 1
}elseif (doc['burn.keyword'].value == "No") {
return -1
}

Hi Matt,

I'm able to create a script like this:

if (doc['geo.src'].value == "US") {
  return 1
}

if (doc['geo.src'].value == "CN") {
  return -1
}

return 0

The script is of type "number" and a format of "default".

It looks like it returns the correct values. Can you give this a shot and if it doesn't work, can you tell me what error you're seeing?

Thanks,
CJ

This works, thanks!

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