Below are two queries with their respective responses. I would like to understand the difference between the below queries from the point of aggregation. In Request 1 I filter docs based on "unique_name" and then group them by "text_value". But should it not return the same response as Request - 2?
Request - 1:
{
"size": 0,
"aggs": {
"custom_field_agg": {
"nested": {
"path": "custom_field"
},
"aggs": {
"filter_custom_field": {
"filter": {
"term": {
"custom_field.unique_name": "PBI or Defect ID"
}
},
"aggs": {
"text_values": {
"terms": {
"field": "custom_field.text_value"
}
}
}
}
}
}
}
}
Response - 1:
{
"took": 287,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 67,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"custom_field_agg": {
"doc_count": 134,
"filter_custom_field": {
"doc_count": 67,
"text_values": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "NA",
"doc_count": 60
},
{
"key": "00000",
"doc_count": 7
}
]
}
}
}
}
}
Request - 2:
{
"size": 0,
"aggs": {
"custom_field_agg": {
"nested": {
"path": "custom_field"
},
"aggs": {
"unique_name": {
"terms": {
"field": "custom_field.unique_name"
},
"aggs": {
"text_values": {
"terms": {
"field": "custom_field.text_value"
}
}
}
}
}
}
}
}
Response - 2:
{
"took": 20,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 67,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"custom_field_agg": {
"doc_count": 134,
"unique_name": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "PBI or Defect ID",
"doc_count": 67,
"text_values": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "NA",
"doc_count": 60
},
{
"key": "00000",
"doc_count": 7
}
]
}
},
{
"key": "Squad Name",
"doc_count": 66,
"text_values": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Automation Team",
"doc_count": 61
},
{
"key": "Avengers",
"doc_count": 1
},
{
"key": "Explorers",
"doc_count": 1
},
{
"key": "Guardians",
"doc_count": 1
},
{
"key": "Incredibles",
"doc_count": 1
},
{
"key": "Justice League",
"doc_count": 1
}
]
}
},
{
"key": "Developer Names",
"doc_count": 1,
"text_values": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Santo John",
"doc_count": 1
}
]
}
}
]
}
}
}
}
Index Mapping :
"custom_field": {
"type": "nested",
"properties": {
"bool_value": {
"type": "integer"
},
"date_value": {
"type": "date"
},
"db_column_name": {
"type": "keyword",
"index": false
},
"is_required": {
"type": "integer",
"index": false
},
"label": {
"type": "text",
"index": false
},
"pid": {
"type": "integer"
},
"text_value": {
"type": "keyword"
},
"unique_name": {
"type": "keyword"
}
}
}