Hi Everyone I am trying to build a JSON with following structure in ESQL-
{
"programId": 0,
"sku": "abc",
"productTypeId": 0,
"brand": "string",
"year_no": 0,
"characteristics": [
{
"characteristicId": 1,
"value_no": "a"
},
{
"characteristicId": 2,
"value_no": "b"
},
{
"characteristicId": 3,
"value_no": "c"
}
]
}
Can anyone help me in the ESQL code structure for the particular use case.
Problems I am facing- When I am using Outputroot.JSON.Data - It is printing Data as root object. How Should I loop through DB to get this result. I am fetching every record from DB. Thanks for help!
I am able to get result for one record but when I am looping it for second it is overwriting the previous values.
Also, I have to match and compare first five fields I have to keep them common and build characteristics array.
EDIT: Based on your comments, you want one message on the output terminal when one of the first 5 elements changes the value. The algorithm assumes that your database fields are sorted by the first 5 elements.
Then the code will look like this, see Creating a JSON message to understand the details:
I tested this code with following input:
This is the first output message:
And this is the second output message: