opendistro-for-elasticsearch / sql

🔍 Open Distro SQL Plugin
https://opendistro.github.io/for-elasticsearch/features/SQL%20Support.html
Apache License 2.0
620 stars 186 forks source link

Issues in querying nested objects #1138

Open newUserForTesting opened 3 years ago

newUserForTesting commented 3 years ago

Hello Experts,

Our Index Mapping has several nested structures and objects within it. Just to showcase the issue, please consider the following sample mapping

PUT /sample_order { "mappings": { "properties": { "orderNo":{ "type": "text" }, "orderLines": { "type": "nested", "properties": { "item": { "type": "object", "properties": { "itemDesc": { "type": "text" },"itemID": { "type": "integer" } } } } } } } }

POST /sample_order/_bulk {"index":{"_id":1}} {"orderNo":"1","orderLines":[{"item":{"itemDesc":"SampleItemDesc1","itemID":11}}]} {"index":{"_id":2}} {"orderNo":"2","orderLines":[{"item":{"itemDesc":"SampleItemDesc2","itemID":22}}]}

Now if we want to run following query: { "query": "SELECT * FROM sample_order where orderLines.item.itemID=11", "fetch_size": 10 } It doesn't return any records.

If we change it to: { "query": "SELECT * FROM sample_order where nested(orderLines.item.itemID)=11", "fetch_size": 10 } It throws error mentioning: nested object under path [orderLines.item] is not of nested type

How can we query objects inside nested structures? Could you please assist in this Experts. We really appreciate your help!

Thanks!

newUserForTesting commented 3 years ago

Could someone please assist in the above query? Appreciate the help.