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

Scriptable Metric Aggregation #5923

Closed
mattweber opened this issue Apr 23, 2014 · 3 comments · Fixed by #7075
Closed

Scriptable Metric Aggregation #5923

mattweber opened this issue Apr 23, 2014 · 3 comments · Fixed by #7075

Comments

@mattweber
Copy link
Contributor

It would be great if we could have a script-based metric aggregation that can
refer to other metric aggregations from within the script. For example, given
the data and query given in this gist:

https://gist.github.com/mattweber/71033b1bf2ebed1afd8e

It would like to be able to do something like the following for a "profit" calculation:

"cost_agg": {
    "filter": {
        "term": {
            "type": "cost"
        }
    },
    "aggs": {
        "cost_sum_agg": {
            "sum": {
                "field": "value"
            }
        }
    }
},
"sale_agg": {
    "filter": {
        "term": {
            "type": "sale"
        }
    },
    "aggs": {
        "sale_sum_agg": {
            "sum": {
                "field": "value"
            }
        }
    }
},
"profit_agg": {
    "metric_script": {
        "script": "sale_agg>sale_sum_agg - cost_agg>cost_sum_agg"
    }
}

So using the data from the gist we would get a response such as:

{
  "key" : "foobar",
  "doc_count" : 4,
  "sale_agg" : {
    "doc_count" : 2,
    "sale_sum_agg" : {
      "value" : 65.48
    }
  },
  "cost_agg" : {
    "doc_count" : 2,
    "cost_sum_agg" : {
      "value" : 24.68
    }
  },
  "profit_agg": {
    "value": 40.80
  }
}

I believe something like this would be possible given the fact that the
the order parameter of a Terms Aggregation can refer to metric sub-aggregation
values. The logic and retrieving the values should be very similar. Exposing
them to a script might be the hard part.

I will look into this further but I wanted to open the issue in case you are
working on similar functionality or have any suggestions for me.

/cc @uboness @jpountz

@uboness
Copy link
Contributor

uboness commented Apr 28, 2014

@mattweber The one thing we have right now in the aggs framework is that each agg is agnostic of other aggs and we'd like to keep it this way. We do have plans to come out with a scriptable metrics agg that will enable you to compute the profit (look at it as a scriptable map/reduce logic)... we'll create a public issue for it soon... I'll keep this one open and once we have the public issue for it will link the two

@mattweber
Copy link
Contributor Author

That sounds great, thanks for the update!

@mattweber
Copy link
Contributor Author

@uboness Just pinging to see if there has been any progress toward functionality that would allow this type of aggregation?

@colings86 colings86 removed the discuss label Jul 28, 2014
@colings86 colings86 self-assigned this Jul 28, 2014
colings86 added a commit that referenced this issue Aug 20, 2014
A metrics aggregation which runs specified scripts at the init, collect, combine, and reduce phases

Closes #5923
colings86 added a commit that referenced this issue Sep 8, 2014
A metrics aggregation which runs specified scripts at the init, collect, combine, and reduce phases

Closes #5923
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants