Hi all,
I've been migrating order & order items one-to-many relation from MySQL into ES using Logstash.
With the help of filter aggregation for my joined SQL, the items
become a nested
property under each order
and they look like this:
"order_metadata": {
"some_data_foo": "123QUX",
"some_data_bar": "4a8d77550086253a0ac3f1",
"some_other_data_baz": "Some Words",
"some_other_data_foo": "9876"
},
"some_order_field": "Foo Bar Baz Qux 123"
"items": [
{
"category": "bar",
"some_json_structure": "{\"size\":\"XL\",\"color\":\"red\",\"depth\":0.2,\"height\":0.6,\"unit\":\"M\"}",
"code": "XYZ002-T004",
"metadata": "{\"location\":\"FooBar\"}",
"quantity": 1,
"price": 5.0,
"name": "Sample Item",
"id": 23966914,
"weight": 0.2
},
{
"category": "foo",
"some_json_structure": "[]",
"code": "XYZ005-T012",
"metadata": "{\"location\":\"FooBar Baz\"}",
"quantity": 2,
"price": 10.0,
"name": "Sample Item 2",
"id": 25966999,
"weight": 0.5
}
],
Originally the order_metadata
field (which is never a nested structure but is made of key: value lists), comes as stringified JSON and using json { source => "order_metadata" }
in filter {}
I can easily parse this into an object
field.
However I cannot seem to parse the stringified JSON fields that are found within the array of objects using json { source => 'items.property_name' }
, such as items.some_json_structure
and items.metadata
seen in the above structure.
To note, items.some_json_structure
that comes in is either []
or an object like in the first item, while items.metadata
that comes in is either an empty string or an object
.
- How can I parse the stringified JSON values of the fields of an object in the array of objects?
- I noticed that doing must match queries that look up an item that has
name
=Sample
ANDcode
=XYZ
take a lot more time to query than top level object properties. Is there any advantage that can be gained by somehow making each item a top level property of the order, mapping them as objects?
Thanks for your time!