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

1.4.0 failed to compile and run native script score function #8377

Closed
andyxukq opened this issue Nov 7, 2014 · 8 comments
Closed

1.4.0 failed to compile and run native script score function #8377

andyxukq opened this issue Nov 7, 2014 · 8 comments
Assignees
Labels

Comments

@andyxukq
Copy link

andyxukq commented Nov 7, 2014

Hi y'all,

After upgrading to 1.4.0, I failed to compile my native(Java) score functions which worked well with 1.3.4.
The first issue I ran into is that my function extended AbstractDoubleSearchScript and call score() to get document score from Lucene, apparently it won't work now with 1.4.0.

I wonder if any of you could tell me which method should be called to get the original score of one document. An example of my function looks like:

public class BasicScorer extends AbstractDoubleSearchScript {

  public static final String NAME = "basic-scorer";

  public static class Factory implements NativeScriptFactory {
    @Override
    public ExecutableScript newScript(@Nullable Map<String, Object> params) {
      return new BasicScorer();
  }

  private BasicScorer() {
  }

  @Override
  public double runAsDouble() {
      return score() * ((ScriptDocValues.Doubles) doc().get("rank")).getValue();
  }
}

The second issue is when I just remove the 'score()' method and query ElasticSearch with following parameter:

...
     "script_score": {
        "script": "basic-scorer",
        "lang": "native"
      }
...

following error was logged:

    at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:665)
    ... 9 more
Caused by: java.lang.UnsupportedOperationException
    at org.elasticsearch.script.AbstractSearchScript.setScorer(AbstractSearchScript.java:104)
    at org.elasticsearch.common.lucene.search.function.ScriptScoreFunction.<init>(ScriptScoreFunction.java:86)

I noticed there were some groovy script function changes, but I don't think that should affect the interface of native score function.

Regards,
Andy

@andyxukq andyxukq changed the title 1.4.0 failed to compile native script score function 1.4.0 failed to compile and run native script score function Nov 7, 2014
@dccmx
Copy link

dccmx commented Nov 7, 2014

Same problem here, and I can not find a way (efficient way) to get the score lucene provided within a native score script.

@clintongormley
Copy link
Contributor

It looks like it is to do with this change: #7819

@brwe can you shed more light here please?

@kilnyy
Copy link

kilnyy commented Nov 8, 2014

I think I have the same issue, I wrote my plugin with the instruction in this repo:
https://github.com/imotov/elasticsearch-native-script-example
and also got UnsupportedOperationException in the log.

@noamt
Copy link

noamt commented Nov 9, 2014

I too suffer from the issue

@rjernst
Copy link
Member

rjernst commented Nov 10, 2014

In 1.3 and before, there was a weird dual API for setting the score (see #6864). The score() function was removed there.

To access the score from a native script, you should @Override setScorer(Scorer) and call scorer.score() on when you want the score.

@rjernst rjernst closed this as completed Nov 10, 2014
@rjernst
Copy link
Member

rjernst commented Nov 10, 2014

After looking at this a little more, the original intention was the score could be accessed with doc().score(), but that was removed with #7819. I've opened #8416 to add back score() for AbstractSearchScript.

@imotov
Copy link
Contributor

imotov commented Nov 10, 2014

@kilnyy, @noamt elasticsearch-native-script-example is updated with a temporary work-around until 1.4.1 is released.

@noamt
Copy link

noamt commented Nov 10, 2014

Cheers!

rjernst added a commit that referenced this issue Nov 10, 2014
@rjernst rjernst added the >bug label Nov 10, 2014
rjernst added a commit that referenced this issue Nov 10, 2014
rjernst added a commit that referenced this issue Nov 10, 2014
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants