-
Notifications
You must be signed in to change notification settings - Fork 1.5k
NestedTypes queries
Eliran Moyal edited this page Nov 28, 2015
·
8 revisions
##Nested Types Read about NestedTypes and what they are good for here
From 1.4.7/2.0.2/2.1.0 version of elasticsearch-sql we have support for using nestedTypes.
We are supporting queries and aggregations! ###Query nested fields
- Simple Query (one field)
In order to query a nested field all you need to do is add the "nested" function on the field.
SELECT * FROM myIndex where nested(comments.message)='hello'
If you want to specify the path implicitly use:
SELECT * FROM myIndex where nested('comments',comments.message)='hello'
- Complex Query (more than one field)
The syntax is simplynested('nested_path',where condition)
for example:
SELECT * FROM myIndex where nested('comments', comments.message = 'hello' and comments.likes > 3)
###Aggregate on nested fields
-
Simple term aggregation
Wrap the string field with nested function
SELECT count(*) as numOfComments FROM myIndex where nested(comments.age) > now-1d
GROUP BY nested(comments.author)
-
Metric aggregations
Just wrap the nested field with nested function
SELECT sum(nested(comments.likes)) as sumOfInnerLikes FROM myIndex
-
Buckets aggregation
Add the 'nested' option like this: the value should be the nested path.
select count(*) from index
group by date_histogram('field'='message.date','interval'='1d','alias'='day', 'nested' ='message')