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

Clearer exception: "Field \'" + name + "\' cannot be used in an expression: it was not registered with sort=true" #79

Open
sarthakn7 opened this issue Apr 6, 2020 · 1 comment

Comments

@sarthakn7
Copy link
Contributor

sarthakn7 commented Apr 6, 2020

This error in FieldDefBindings: throw new IllegalArgumentException("Field \'" + name + "\' cannot be used in an expression: it was not registered with sort=true"); is essentially thrown when either the field is not virtual or is a field (including numeric) not having doc values type DocValuesType.NUMERIC. So this error can even be thrown if either the field was not numeric, or was numeric but multivalued, or was numeric but doc values were not stored. Adding sort: true for the fields in such cases will still keep throwing this error. We can probably change this exception to reflect the required condition, i.e. the field type is not virtual or does not have NUMERIC doc values.

@umeshdangat
Copy link
Member

Seems like this is an issue when trying to retrieve multivalued doc values in expressions. Lucene Bindings base class is somewhat limited in that it can return DoubleValuesSource which support only single double values.

Code flow

The issue happens when using FunctionScoreQuery, which is creates like
FunctionScoreQuery(Query in, DoubleValuesSource source)

We extend Bindings class and override
public DoubleValuesSource getDoubleValuesSource(String name)

DoubleValuesSource API in lucene seems to support only getting a single double value
public abstract DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException

We can have implementations our own DoubleValuesSource to support custom functions to retrieve specific value from a multivalued field like

Also if the script is just referring to a multiValued field in an Expression we should throw a more comprehend able exception.

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

No branches or pull requests

2 participants