Skip to content

Scripting: Ambiguous resolution of _doc.score #7043

Closed
@jpountz

Description

@jpountz

Some scripting languages don't make a difference between property access foo.bar and map lookups foo['bar']. This is an issue for the DocLookup class (which is the class behind the _doc variable and implements java.util.Map) since there are two ways that _doc.score can be resolved:

  1. DocLookup.getScore()
  2. DocLookup.get("score").

The interesting thing is that mvel translates _doc.score to getScore while Groovy seems to translate it to get("score"). So when trying to lookup the score in Groovy, you might see the following error:

GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No field found for [score] in mapping with types [index_name]].

For reference, if you encounter this issue, you can work around it by using _score instead of _doc.score. So maybe the way to go would be to deprecate _doc.score and make scripting engines expose the score via _score instead. I tend to find it cleaner as well since the score is not really a property of the document (it also depends on the query).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions