Created
August 22, 2020 11:36
-
-
Save etki/677b2d570520029f4b6a45646405a67b to your computer and use it in GitHub Desktop.
Nested elasticsearch agg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PUT localhost:9200/index | |
{ | |
"mappings": { | |
"properties": { | |
"nested": { | |
"type": "nested", | |
"properties": { | |
"values": { | |
"type": "keyword" | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PUT localhost:9200/index/_doc/1 | |
{ | |
"nested": { | |
"values": ["1", "2", "1"] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PUT localhost:9200/index/_doc/2 | |
{ | |
"nested": { | |
"values": ["1", "3"] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# POST localhost:9200/index/_search | |
{ | |
"size": 0, | |
"aggs": { | |
"root": { | |
"terms": { | |
"field": "_id" | |
}, | |
"aggs": { | |
"values": { | |
"nested": { | |
"path": "nested" | |
}, | |
"aggs": { | |
"combined": { | |
"terms": { | |
"field": "nested.values" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"took": 19, | |
"timed_out": false, | |
"_shards": { | |
"total": 1, | |
"successful": 1, | |
"skipped": 0, | |
"failed": 0 | |
}, | |
"hits": { | |
"total": { | |
"value": 2, | |
"relation": "eq" | |
}, | |
"max_score": null, | |
"hits": [] | |
}, | |
"aggregations": { | |
"root": { | |
"doc_count_error_upper_bound": 0, | |
"sum_other_doc_count": 0, | |
"buckets": [ | |
{ | |
"key": "1", | |
"doc_count": 1, | |
"values": { | |
"doc_count": 1, | |
"combined": { | |
"doc_count_error_upper_bound": 0, | |
"sum_other_doc_count": 0, | |
"buckets": [ | |
{ | |
"key": "1", | |
"doc_count": 1 | |
}, | |
{ | |
"key": "2", | |
"doc_count": 1 | |
} | |
] | |
} | |
} | |
}, | |
{ | |
"key": "2", | |
"doc_count": 1, | |
"values": { | |
"doc_count": 1, | |
"combined": { | |
"doc_count_error_upper_bound": 0, | |
"sum_other_doc_count": 0, | |
"buckets": [ | |
{ | |
"key": "1", | |
"doc_count": 1 | |
}, | |
{ | |
"key": "3", | |
"doc_count": 1 | |
} | |
] | |
} | |
} | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment