Hello,
I am doing a lookup from logstash into Elasticsearch before loading my data, I am running into issue when the data in log file is in array format, e.g. below is my log line:
{"id":1652437414971,"body":{"data":[{"product":"6274c6408085c1476cbd1023"}]},"function":"saveOrder","type":"REQ"
I am parsing the above json and then using below code in logstash config file:
if [function] == "saveOrder" and [type] == "REQ"{
   elasticsearch {
   hosts => ["https://*.*.*.*:****"]
   index => "products-search"
   user => "*********"
   password => "*********"
   query_template => "/etc/logstash/conf.d/query-categories.json"
   fields => { "category" => "categoryName"
                     "subCategory" => "subCategoryName"
                   }
            }
    }
My query_template is below:
{"size": 1,"query":{"match":{"productId": "%{[body][data][product]}"}}}
However, there are no hits, logstash output is as below
{
          "body" => {
        "data" => [
            [0] {
                "product" => "6274c6408085c1476cbd1023"
            }
        ]
    },
      "function" => "saveOrder",
          "type" => "REQ",
            "id" => 1652437414971
}
Now if I remove the square array brackets ( [ ] ) from data field in the log line and change it to below:
{"id":1652437414971,"body":{"data":{"product":"6274c6408085c1476cbd1023"}},"function":"saveOrder","type":"REQ"}
The query returns the data correctly in logstash output:
{
           "function" => "saveOrder",
       "categoryName" => "ELECTRONICS",
               "body" => {
        "data" => {
            "product" => "6274c6408085c1476cbd1023"
        }
    },
                   "type" => "REQ",
    "subCategoryName" => "Mobile",
                 "id" => 1652437414971
}
Where do I need to make the relevant changes (logstash conf or query_template) to take care of the array?