Hello. I want to make Global nested aggregation with nested field inside nested field. And it doesn't works. I am not sure why.
I have this kind of structure (mapping added down), where embellishmentMethodsData
is nested and productionTimeList
is nested.
embellishmentMethodsData: [
{
method: 'debossed',
productionTimeList: [
{
name: 'Standard',
cost: 0,
time: 18,
},
{
name: 'Super Speed',
time: 1,
cost: 0,
},
],
isSuperSpeed: true,
superSpeedSettings: {
minQuant: 100,
maxQuant: 100000,
maxPrintColors: 0,
},
},
{
method: 'digital print',
isSuperSpeed: false,
productionTimeList: [
{
name: 'Standard',
cost: 0,
time: 50,
},
],
},
{
method: 'heat transfer',
isSuperSpeed: false,
productionTimeList: [
{
name: 'Standard',
cost: 0,
time: 50,
},
],
},
]
I want to return all unique embellishmentMethodsData.method
where embellishmentMethodsData.isSuperSpeed: true
AND embellishmentMethodsData.productionTimeList.name: "Super Speed"
.
Query works well (documents filtered in the right way), but Global aggregation gives wrong results - all embellishmentMethodsData.methods
added where embellishmentMethodsData.isSuperSpeed: true
, but another filter embellishmentMethodsData.productionTimeList.name: "Super Speed"
is not applied.
Here is my mapping.
{
"light_integration_development_products": {
"mappings": {
"properties": {
"categories": {
"properties": {
"categoryId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"isDefault": {
"type": "boolean"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"embellishmentMethodsData": {
"type": "nested",
"properties": {
"isSuperSpeed": {
"type": "boolean"
},
"method": {
"type": "keyword",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"productionTimeList": {
"type": "nested",
"properties": {
"cost": {
"type": "long"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"time": {
"type": "long"
}
}
},
"superSpeedSettings": {
"properties": {
"maxPrintColors": {
"type": "long"
},
"maxQuant": {
"type": "long"
},
"minQuant": {
"type": "long"
}
}
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
Here is my all 3 DOCUMENTS
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "light_integration_development_products",
"_type": "_doc",
"_id": "5df8f442ae53c265bfdc1b77",
"_score": 1.0,
"_source": {
"name": "Recycled Cotton Tote 333",
"embellishmentMethodsData": [
{
"method": "blue inc",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 30
}
]
}
],
"categories": [
{
"isDefault": true,
"name": "Totes",
"categoryId": "57ed30cb0a0cab3686ccaae7"
}
]
}
},
{
"_index": "light_integration_development_products",
"_type": "_doc",
"_id": "5df8f442ae53c265bfdc1b76",
"_score": 1.0,
"_source": {
"name": "Recycled Cotton Tote 222",
"embellishmentMethodsData": [
{
"method": "embroidery",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 25
},
{
"name": "Super Speed",
"cost": 0,
"time": 5
}
],
"isSuperSpeed": true,
"superSpeedSettings": {
"minQuant": 50,
"maxQuant": 1000,
"maxPrintColors": 0
}
}
],
"categories": [
{
"isDefault": true,
"name": "Totes",
"categoryId": "57ed30cb0a0cab3686ccaae7"
}
]
}
},
{
"_index": "light_integration_development_products",
"_type": "_doc",
"_id": "5df8f442ae53c265bfdc1b75",
"_score": 1.0,
"_source": {
"name": "Recycled Cotton Tote",
"embellishmentMethodsData": [
{
"method": "debossed",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 18
},
{
"name": "Super Speed",
"time": 1,
"cost": 0
}
],
"isSuperSpeed": true,
"superSpeedSettings": {
"minQuant": 100,
"maxQuant": 100000,
"maxPrintColors": 0
}
},
{
"method": "digital print",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 50
}
]
},
{
"method": "heat transfer",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 50
}
]
}
],
"categories": [
{
"isDefault": true,
"name": "Totes",
"categoryId": "57ed30cb0a0cab3686ccaae7"
}
]
}
}
]
}
}
Here is my REQUEST:
{
"from": 0,
"size": 12,
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"nested": {
"path": "embellishmentMethodsData",
"query": {
"bool": {
"must": [
{
"term": {
"embellishmentMethodsData.isSuperSpeed": true
}
}
]
}
}
}
}
]
}
}
],
"should": [
{
"exists": {
"field": "categories"
}
}
],
"minimum_should_match": 1
}
},
"aggs": {
"embellishmentMethodsGlobal": {
"global": {},
"aggs": {
"unfilteredFacets": {
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"nested": {
"path": "embellishmentMethodsData",
"query": {
"bool": {
"must": [
{
"term": {
"embellishmentMethodsData.isSuperSpeed": true
}
}
]
}
}
}
},
{
"nested": {
"path": "embellishmentMethodsData.productionTimeList",
"query": {
"bool": {
"filter": [
{
"term": {
"embellishmentMethodsData.productionTimeList.name.keyword": "Super Speed"
}
}
]
}
}
}
}
]
}
}
],
"should": [
{
"exists": {
"field": "categories"
}
}
],
"minimum_should_match": 1
}
},
"aggs": {
"nestedEmbellishmentMethodsUnique": {
"nested": {
"path": "embellishmentMethodsData"
},
"aggs": {
"embellishmentMethods": {
"terms": {
"size": 50,
"field": "embellishmentMethodsData.method.keyword",
"min_doc_count": 1
}
}
}
}
}
}
}
}
}
}
Here is my RESPONSE
at embellishmentMethodsGlobal buckets I expect only 2 methods - debossed
and embroidery
because they both have
embellishmentMethodsData.isSuperSpeed: true
and embellishmentMethodsData.productionTimeList.name: Super Speed
at 5df8f442ae53c265bfdc1b75
and 5df8f442ae53c265bfdc1b76
documents respectively
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1.1823215,
"hits": [
{
"_index": "light_integration_development_products",
"_type": "_doc",
"_id": "5df8f442ae53c265bfdc1b76",
"_score": 1.1823215,
"_source": {
"name": "Recycled Cotton Tote 222",
"embellishmentMethodsData": [
{
"method": "embroidery",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 25
},
{
"name": "Super Speed",
"cost": 0,
"time": 5
}
],
"isSuperSpeed": true,
"superSpeedSettings": {
"minQuant": 50,
"maxQuant": 1000,
"maxPrintColors": 0
}
}
],
"categories": [
{
"isDefault": true,
"name": "Totes",
"categoryId": "57ed30cb0a0cab3686ccaae7"
}
]
}
},
{
"_index": "light_integration_development_products",
"_type": "_doc",
"_id": "5df8f442ae53c265bfdc1b75",
"_score": 1.1823215,
"_source": {
"name": "Recycled Cotton Tote",
"embellishmentMethodsData": [
{
"method": "debossed",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 18
},
{
"name": "Super Speed",
"time": 1,
"cost": 0
}
],
"isSuperSpeed": true,
"superSpeedSettings": {
"minQuant": 100,
"maxQuant": 100000,
"maxPrintColors": 0
}
},
{
"method": "digital print",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 50
}
]
},
{
"method": "heat transfer",
"productionTimeList": [
{
"name": "Standard",
"cost": 0,
"time": 50
}
]
}
],
"categories": [
{
"isDefault": true,
"name": "Totes",
"categoryId": "57ed30cb0a0cab3686ccaae7"
}
]
}
}
]
},
"aggregations": {
"embellishmentMethodsGlobal": {
"doc_count": 3,
"unfilteredFacets": {
"doc_count": 2,
"nestedEmbellishmentMethodsUnique": {
"doc_count": 4,
"embellishmentMethods": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "debossed",
"doc_count": 1
},
{
"key": "digital print",
"doc_count": 1
},
{
"key": "embroidery",
"doc_count": 1
},
{
"key": "heat transfer",
"doc_count": 1
}
]
}
}
}
}
}
}
Can somebody show me how to fix this please or maybe you know how to debug this? Is there a way to see aggregated documents somehow?