Add new field based on the result of array

I have part of JSON appearing as below:
{ "SampleName" => [
[0] "name1",
[1] "name2",
[2] "name3",
[3] "name4"
],
}
I want to do the following:
If the SampleName[0] is equal to name1, create a field called Value1.
If the SampleName[1] is equal to name2, create a field called Value2.

I am doing the following, but no match. Can you please let me know where is my mistake?
if "SampleName[0]"=~ "name1" {
mutate {
add_field => { "Value1" => "test" }
}
}

Got it!
It will be:
if [SampleName][0] == "name1" {
mutate {
add_field => { "Value1" => "test" }
}
}

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