How to access field value with LeafReaderContext in ScriptEngine

I am trying to create my customized ScriptEngine. In my case my data like
{
"body": "a b c a"
}

{
  "body": "a b a a"
}

I want to access the body value "a b a a" during the ScoreScript.execute process. How I can do that?

private static class PureDfLeafFactory implements LeafFactory {

  @Override
  public ScoreScript newInstance(LeafReaderContext context)
  throws IOException {
    // is the any way to access field `body`'s value here
  }
}

Is the body field analyzed? If it is, you'll need to copy the field to a keyword field which can be stored in doc values. Then access the field through the context.reader().getSortedSetDocValues() method.

Note that this is not advisable: doing string parsing in a scoring script is going to destroy performance.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.