Hi all!
I have found the next behavior during aggregation.
Let's create a simple document:
PUT example
{
"mappings": {
"_doc": {
"properties": {
"products": {
"type": "object",
"properties": {
"category": {
"type": "object",
"properties": {
"name": {
"type": "keyword",
"store": true
},
"rank": {
"type": "long",
"store": true
}
}
}
}
}
}
}
}
}
Than add one document:
PUT example/_doc/1
{
"products": [
{
"category": {
"name": "Category 1",
"rank": 1
}
},
{
"category": {
"name": "Category 2",
"rank": 2
}
}
]
}
I want to aggregate by category name and category rank, so my aggregation query is:
POST example/_search
{
"aggs": {
"agg_docs_category_name": {
"terms": {
"field": "products.category.name"
},
"aggs": {
"agg_docs_category_rank": {
"terms": {
"field": "products.category.rank"
}
}
}
}
}
}
I expected to receive that I have "Category 1" with rank "1" and "Category 2" with rank "2" for this document, but I received:
{
"aggregations": {
"agg_docs_category_name": {
"buckets": [
{
"key": "Category 1",
"doc_count": 1,
"agg_docs_category_rank": {
"buckets": [
{
"key": 1,
"doc_count": 1
},
{
"key": 2,
"doc_count": 1
}
]
}
},
{
"key": "Category 2",
"doc_count": 1,
"agg_docs_category_rank": {
"buckets": [
{
"key": 1,
"doc_count": 1
},
{
"key": 2,
"doc_count": 1
}
]
}
}
]
}
}
}
So, looks like ranks and categories just multiplied. How to avoid this?
Thanks in advance,
Vova