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

[console] highlighting for scripted metric agg scripts #15377

Merged
merged 4 commits into from
Mar 30, 2018

Conversation

jbudz
Copy link
Member

@jbudz jbudz commented Dec 4, 2017

Rebased #13606 with a small fix on top. Credit to @jpcarey.

This adds highlighting detection to scripted metric aggregation scripts when using the """<script> syntax. Elasticsearch docs.

Before:
image

After:
image

Testing:

POST ledger/_search?size=0
{
    "aggs": {
        "profit": {
            "scripted_metric": {
                "map_script" :"""

params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)

"""
            }
        }
    }
}

@jpcarey
Copy link

jpcarey commented Jan 9, 2018

@jbudz I noticed this hasn't been merged yet. It needs one more modification for 6.x. inline -> source:

("(?:[^"]*_)?script"|"inline"|"source")(\\s*?)(:)(\\s*?)(""")

elastic/elasticsearch#25127

@elasticmachine
Copy link
Contributor

💔 Build Failed

jpcarey and others added 4 commits March 30, 2018 13:06
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"
            }
        }
    }
}
```
@jbudz
Copy link
Member Author

jbudz commented Mar 30, 2018

/cc @elastic/kibana-management if anyone gets a moment to review

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

LGTM!

@jbudz jbudz merged commit 9754b6c into elastic:master Mar 30, 2018
jbudz added a commit that referenced this pull request Mar 30, 2018
* highlighting for scripted metric agg scripts

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"
            }
        }
    }
}
```

* Update x_json_highlight_rules.js

* [console] Remove capture group from *_script check

* allow source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants