# How to access doc values in LeafScoreFunction (noobie)

**URL:** <https://discuss.elastic.co/t/how-to-access-doc-values-in-leafscorefunction-noobie/127112>\
**Category:** Elasticsearch\
**Created:** [April 6, 2018, 1:58pm UTC](https://discuss.elastic.co/t/how-to-access-doc-values-in-leafscorefunction-noobie/127112 "2018-04-06T13:58:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephencoffman](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@stephencoffman](https://discuss.elastic.co/u/stephencoffman)\
**Post date:** [April 6, 2018, 1:58pm UTC](https://discuss.elastic.co/t/how-to-access-doc-values-in-leafscorefunction-noobie/127112/1 "2018-04-06T13:58:41Z")

</div>

ES 6.2.3

I'm trying to write a SearchPlugin to do custom scoring, but I can't figure out how to access the doc values in my leaf score function.

The LeafScoreFunction.score() method takes a docId parameter. Is there a way to use that to get to the doc values.

Also, where is the proper place to get access to the document? In the LeafScoreFunction methods? Should I get access to it in the ScoreFunction.getLeafScoreFunction() method and pass it in to my LeafScoreFunction? Somewhere else?

Thank you very much for helping.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [April 6, 2018, 3:43pm UTC](https://discuss.elastic.co/t/how-to-access-doc-values-in-leafscorefunction-noobie/127112/2 "2018-04-06T15:43:07Z")

</div>

It looks like you are attempting to implement a FunctionScoreQuery. This class doesn't itself know anything about Lucene, only some implementations do (like ScriptScoreFunction). Maybe consider using an advanced script instead. The [docs for writing native scripts](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-engine.html) (through a custom script engine) explain how to access Lucene data structures.

---

<div class="post-metadata">

**Author:** ![stephencoffman](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@stephencoffman](https://discuss.elastic.co/u/stephencoffman)\
**Post date:** [April 6, 2018, 10:01pm UTC](https://discuss.elastic.co/t/how-to-access-doc-values-in-leafscorefunction-noobie/127112/3 "2018-04-06T22:01:17Z")

</div>

Thank you Ryan, that sent me in the right direction.  
The [ExplainableScript integration test](https://github.com/elastic/elasticsearch/blob/v6.2.3/server/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java) was also very helpful.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 4, 2018, 10:01pm UTC](https://discuss.elastic.co/t/how-to-access-doc-values-in-leafscorefunction-noobie/127112/4 "2018-05-04T22:01:18Z")

</div>

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