Kevin
Kevin

Reputation: 25269

elastic search top_hits aggregation with lucene expression

I want to do a field collapse top hits aggregation, exactly as documented here:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html#_field_collapse_example

In particular, this segment is a problem:

"top_hit": {
    "max": {
        "script": "_score"
    }
}

Because the production environment is configured with:

script.disable_dynamic: sandbox

Which means I can't use groovy scripts, without getting an error along these lines:

nested: ScriptException[dynamic scripting for [groovy] disabled];

If I change the query like so:

"top_hit": {
    "max": {
        "lang": "expression",
        "script": "_score"
    }
}

I get a different type of error:

nested: IllegalStateException[Expressions referencing the score can only be used for sorting];

The elastic search version is 1.5.2. Is there a way to do what I want (with lucene expressions)?

Upvotes: 1

Views: 458

Answers (1)

Kevin
Kevin

Reputation: 25269

I found the answer after a little bit of googling. This was a known issue which was fixed.

https://github.com/elastic/elasticsearch/issues/10091

It's unclear which version it is fixed in, however.

Upvotes: 0

Related Questions