I need help regarding elastic search mapping of nested json document. I search in web a lot but didnt find any good to the point info. Suppose I have this type of data..
{ "name" : "Zach", "car" : [ { "make" : "Saturn", "model" : "SL" }, { "make" : "Subaru", "model" : "Imprezza" } ] } { "name" : "Bob", "car" : [ { "make" : "Saturn", "model" : "Imprezza" } ] }
where car can have any number of data objects inside. According to the elastic search doc I came to know that for nested json I have to specify the type as nested. But there has no information regarding how I will specify the mapping info of variables under that nested type.
Like in the example above I can write the mapping like this.
{ "person":{ "properties":{ "name" : { "type" : "string" }, "car":{ "type" : "nested" } } } }
but how to provide mapping info for car.make
& car.model
??
Will this work fine without any future problem?
{ "person": { "properties": { "name" : { "type" : "string" }, "car": { "type" : "nested" "properties": { "make": {....}, "model": {....} } } } } }
The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way that they can be queried independently of each other.
The inner hits feature can be used for this. This feature returns per search hit in the search response additional nested hits that caused a search hit to match in a different scope. Inner hits can be used by defining an inner_hits definition on a nested , has_child or has_parent query and filter.
When a packed class contains an instance field that is a packed type, the data for that field is packed directly into the containing class. The field is known as a nested field .
Nested data types are structured data types for some common data patterns. Nested data types support structs, arrays, and maps. A struct is similar to a relational table. It groups object properties together.
You can do it like this:
PUT /my_index { "mappings": { "blogpost": { "properties": { "comments": { "type": "nested", "properties": { "name": { "type": "string" }, "comment": { "type": "string" }, "age": { "type": "short" }, "stars": { "type": "short" }, "date": { "type": "date" } } } } } } }
Quote from this section of the ES definitive guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With