Scripted Field matching two values with AND statement


(Butch) #1

Hi -

I'm trying to create a scripted field in Kibana that checks the value of two fields then returns 0 or 1 depending on whether they match the values shown below.

My script is:

if (doc['counter.name'].value == '% items OK') && (doc['counter.value'].value == '100') {
   return 0
} else {
   return 1
}

For some reason this is failing with a "Courier Fetch: 2 of 131 shards failed". Does anyone know where my problem is?

Thanks,
Butch


(Bhavya R M) #2

Hi,

Which version of the stack you are on? We have a preview and validate your scripted fields in 6.4.0.

I suspect this might be the problem? '% items OK' What's the % in here?

Thanks
Bhavya


(Butch) #3

Hi Bhavya -

I'm running 6.2. The '% items OK' is the value of 'counter.name' that I'm trying to match. Do I need to backslash the %?

Thanks for your response,
Butch


(Butch) #4

To follow up - this code is now working. I found that this will only work on fields that are listed as "aggregatable".

if ((doc['counter.name.keyword'].value == '% items OK') && (doc['counter.value.keyword'].value == '100')) { return 100; } else { return 1; }

(system) #5

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