I'm brand new to painless, so please forgive me if I'm asking a dumb question here.
I have an index that has events with many fields in them, and need to calculate a field based on values found in others, and include this field in the result.
Thing is I've never done any Painless before, and I'm hoping someone can help me out here.
The logic I need to implement is :
If field_A = "-" or ""
if field_B = "YES" or "MAYBE"
My_calculated_field = "OK"
else
My_calculated_field = "Not OK"
else
My_calculated_field = "Not OK"
If field_A has rubbish data in it (Empty or just a - ) and field_B is one of two particular values, create a field that has "OK" in it.
The field should always be created for every document.
Here's what I have so far, and I'm not getting anywhere with it.
The main question why doc does not exist is about the context in which this script is called, thus my question about the full request including the script.
Something else occurred to me, I could also probably do this in logstash with grok, creating the field at ingestion time.
I'm thinking query time is better in a CPU usage sense, as the processing will be applied on a far smaller number of documents. Would you agree with that?
Doing it at index time is often the better option as you do it once for each document instead of once for every query. It also speeds up queries and scales better.
Thanks for that. Unfortunately, I'm just as new at grok, and my attempts at implementing this don't seem to be working out. Are you able to help me figure out what I'm doing wrong?
if ([field_A] in ["-", ""]) and ([field_B] in ["YES", "MAYBE"]) {
mutate { add_field { "My_calculated_field" => "OK" } }
} else {
mutate { add_field { "My_calculated_field" => "Not OK" } }
}
I keep getting errors when trying to start logstash, an excerpt :
:message=>"Expected one of [ \\t\\r\\n], \"x\", \"=>\" at line 33
Leading me to think that I've missed a closing } somewhere, but I can't see it. Can you?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.