checked Bucket Script Aggregation A parent pipeline aggregation which executes a script which can perform per bucket computations on specified metrics in the parent multi-bucket aggregation. The specified metric must be numeric and the script must return a numeric value.
when using bucket script I am having the below query,but unable to print 1000 for product_id= 6435532 when _count ==0 or [] instead it doesn't print anything. please help. it is working fine when _count > 0.
POST index_name/_search?size=0
{
"aggs": {
"group by products": {
"terms": {
"field": "product_id.keyword",
},
"aggs": {
"filter for PVW": {
"filter": {
"term": {
"event_type.keyword": "PVW"
}
}
},
"group_by_CIP": {
"terms": {
"field": "event_type.keyword",
"include": "CIP"
},
"aggregations": {
"print product id": {
"aggs": {
"CIP doc count": {
"bucket_script": {
"buckets_path": {
"var1": "_count"
},
"script": "if (params.var1 == 'N/A') {1000 } else { params.var1 }" -- unable to print 1000 for _count value Null or 0 value
}
}
},
"terms": {
"field": "web_prod_id.keyword"
}
}
}
}
}
}
} }
output looks like
"aggregations": {
"group by products": {
"doc_count_error_upper_bound": 111,
"sum_other_doc_count": 115547,
"buckets": [
{
"key": "6435532",
"doc_count": 282,
"group_by_CIP": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
},
"filter for PVW": {
"doc_count": 282
}
},
{
"key": "5697273",
"doc_count": 247,
"group_by_CIP": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "CIP",
"doc_count": 13,
"print product id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "5697273",
"doc_count": 13,
"CIP doc count": {
"value": 13
}
}
]
}
}
]
},
"filter for PVW": {
"doc_count": 234
}
}
]
}
} }
any one facing this same issue?
Aucun commentaire:
Enregistrer un commentaire