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

highlighting for scripted metric agg scripts #13606

Closed
wants to merge 2 commits into from
Closed

Conversation

jpcarey
Copy link

@jpcarey jpcarey commented Aug 20, 2017

Adding detection for scripted metric aggregations

POST ledger/_search?size=0
{
    "query" : {
        "match_all" : {}
    },
    "aggs": {
        "profit": {
            "scripted_metric": {
                "init_script" : "params._agg.transactions = []",
                "map_script" : "params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)", 
                "combine_script" : "double profit = 0; for (t in params._agg.transactions) { profit += t } return profit",
                "reduce_script" : "double profit = 0; for (a in params._aggs) { profit += a } return profit"
            }
        }
    }
}

Adding detection for [scripted metric aggregations](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-metrics-scripted-metric-aggregation.html)

```json
POST ledger/_search?size=0
{
    "query" : {
        "match_all" : {}
    },
    "aggs": {
        "profit": {
            "scripted_metric": {
                "init_script" : "params._agg.transactions = []",
                "map_script" : "params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)", 
                "combine_script" : "double profit = 0; for (t in params._agg.transactions) { profit += t } return profit",
                "reduce_script" : "double profit = 0; for (a in params._aggs) { profit += a } return profit"
            }
        }
    }
}
```
@jpcarey jpcarey requested a review from bleskes August 20, 2017 20:40
Copy link
Contributor

@bleskes bleskes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. My suggestion would be to just match "([^"]*_)?script" which will be future proof.

@jpcarey
Copy link
Author

jpcarey commented Aug 21, 2017

@bleskes if we expect all fields will be something_script, then I'll change to your suggestion.

@bleskes
Copy link
Contributor

bleskes commented Aug 21, 2017

I think we can expect that, yeah - though you know, the world isn't perfect. I think we'll catch more things this way and we can always fix when we run into a problem

@jbudz
Copy link
Member

jbudz commented Aug 23, 2017

CI failures look legitimate, taking a look.

@jbudz jbudz self-assigned this Aug 23, 2017
@jbudz
Copy link
Member

jbudz commented Aug 23, 2017

Not matching?

image

@jbudz
Copy link
Member

jbudz commented Dec 4, 2017

Ace is parsing by array index so we had to add a non capture group. Reopened at #15377.

@jbudz jbudz closed this Dec 4, 2017
@jpcarey jpcarey deleted the jpcarey-patch-1 branch December 4, 2017 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants