Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessing parent metric in buckets. #17227

Open
Shivacharangoud opened this issue Feb 3, 2025 · 0 comments
Open

accessing parent metric in buckets. #17227

Shivacharangoud opened this issue Feb 3, 2025 · 0 comments
Labels
bug Something isn't working _No response_ untriaged

Comments

@Shivacharangoud
Copy link

Describe the bug

sample data:
POST sales_data/_bulk
{ "index": { "_id": 1 } }
{ "category": "electronics", "sales": 200 }
{ "index": { "_id": 2 } }
{ "category": "electronics", "sales": 100 }
{ "index": { "_id": 3 } }
{ "category": "furniture", "sales": 150 }
{ "index": { "_id": 4 } }
{ "category": "furniture", "sales": 200 }
{ "index": { "_id": 5 } }
{ "category": "clothing", "sales": 50 }
{ "index": { "_id": 6 } }
{ "category": "clothing", "sales": 100 }
{ "index": { "_id": 7 } }
{ "category": "electronics", "sales": 300 }
{ "index": { "_id": 8 } }
{ "category": "furniture", "sales": 250 }
{ "index": { "_id": 9 } }
{ "category": "clothing", "sales": 150 }

query:

GET sales_data/_search
{
"size": 0,
"aggs": {
"total_sales": {
"sum": { "field": "sales" }
},
"sales_per_category": {
"terms": {
"field": "category.keyword",
"size": 10
},
"aggs": {
"category_sales": {
"sum": { "field": "sales" }
},
"sales_percentage": {
"bucket_script": {
"buckets_path": {
"categorySales": "category_sales",
"totalSales": "../total_sales"
},
"script": "params.categorySales / params.totalSales*100"
}
}
}
}
}
}

and the response from opensearch:
{
"error": {
"root_cause": [
{
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: No aggregation found for path [../total_sales];"
}
],
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: No aggregation found for path [../total_sales];"
},
"status": 400
}

iam trying to access the total_sales inside each bucket to that i can perform percentage of sales in each bucket per total sales.but iam getting and error as shown above. is there any solutions for this?

Related component

No response

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

iam expecting percentage of sales in each category.

Additional Details

  • OS: aws opensearch
  • Version 2.1
@Shivacharangoud Shivacharangoud added bug Something isn't working untriaged labels Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working _No response_ untriaged
Projects
None yet
Development

No branches or pull requests

1 participant