# Getting more than just a score out of a search script

**URL:** <https://discuss.elastic.co/t/getting-more-than-just-a-score-out-of-a-search-script/20048>\
**Category:** Elasticsearch\
**Created:** [October 2, 2014, 12:06pm UTC](https://discuss.elastic.co/t/getting-more-than-just-a-score-out-of-a-search-script/20048 "2014-10-02T12:06:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klaus\_Brunner](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@Klaus\_Brunner](https://discuss.elastic.co/u/Klaus_Brunner)\
**Post date:** [October 2, 2014, 12:06pm UTC](https://discuss.elastic.co/t/getting-more-than-just-a-score-out-of-a-search-script/20048/1 "2014-10-02T12:06:52Z")

</div>

We're making extensive use of custom scoring (implemented in Java). One of  
the problems we've encountered is that we'd love to get not just the score,  
but other data that result from the score function out of Elasticsearch.  
For example, this could be a flag marking certain documents, or some sort  
of custom score explanation, or even another "score" (if you need multiple  
dimensions perhaps).

So far, I haven't found any way of doing this. Search scripts simply return  
a float. There doesn't seem to be anything like a "search context" to  
decorate the returned results, at least not in the way I need it.

Any other ideas?

Thanks

Klaus

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [October 2, 2014, 1:39pm UTC](https://discuss.elastic.co/t/getting-more-than-just-a-score-out-of-a-search-script/20048/2 "2014-10-02T13:39:22Z")

</div>

Hello Klaus ,

For document flagging or similar feature , you can use script filter with  
caching to achieve something close to it -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Also in ES 1.4.0 , there is support for scripted aggregation. Which can  
like implement any custom aggregation logic.  
Hope these might help in your use case.

Thanks  
Vineeth

On Thu, Oct 2, 2014 at 5:06 AM, Klaus Brunner [klaus.brunner@gmail.com](mailto:klaus.brunner@gmail.com)  
wrote:

> We're making extensive use of custom scoring (implemented in Java). One of  
> the problems we've encountered is that we'd love to get not just the score,  
> but other data that result from the score function out of Elasticsearch.  
> For example, this could be a flag marking certain documents, or some sort  
> of custom score explanation, or even another "score" (if you need multiple  
> dimensions perhaps).
> 
> So far, I haven't found any way of doing this. Search scripts simply  
> return a float. There doesn't seem to be anything like a "search context"  
> to decorate the returned results, at least not in the way I need it.
> 
> Any other ideas?
> 
> Thanks
> 
> Klaus
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5ksO3L9iePjWm2dg%3DFj\_-RJeG%2BdJMEg2fPi6BMZKY4rBQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5ksO3L9iePjWm2dg%3DFj_-RJeG%2BdJMEg2fPi6BMZKY4rBQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Klaus\_Brunner](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@Klaus\_Brunner](https://discuss.elastic.co/u/Klaus_Brunner)\
**Post date:** [October 3, 2014, 6:50am UTC](https://discuss.elastic.co/t/getting-more-than-just-a-score-out-of-a-search-script/20048/3 "2014-10-03T06:50:19Z")

</div>

Hi Vineeth,

thanks for the hints, but I'm not sure I understand how this would help. A  
filter script would allow me to remove documents from the next phase and  
thus the result set, but there seems to be no way to annotate the results,  
unless I'm missing something obvious here?

What I'm really looking for is a way to get more than a float out of  
scoring (or maybe filtering if that's easier, though it makes more sense in  
the scoring phase for us). So far we've had to work with some rather  
"creative" solutions to pack more than a single value into the score, but  
those are really nasty hacks.

Klaus

On Thursday, 2 October 2014 15:39:36 UTC+2, vineeth mohan wrote:

> Hello Klaus ,
> 
> For document flagging or similar feature , you can use script filter with  
> caching to achieve something close to it -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html#query-dsl-script-filter)
> 
> Also in ES 1.4.0 , there is support for scripted aggregation. Which can  
> like implement any custom aggregation logic.  
> Hope these might help in your use case.
> 
> Thanks  
> Vineeth
> 
> On Thu, Oct 2, 2014 at 5:06 AM, Klaus Brunner \<[klaus....@gmail.com](mailto:klaus....@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > We're making extensive use of custom scoring (implemented in Java). One  
> > of the problems we've encountered is that we'd love to get not just the  
> > score, but other data that result from the score function out of  
> > Elasticsearch. For example, this could be a flag marking certain documents,  
> > or some sort of custom score explanation, or even another "score" (if you  
> > need multiple dimensions perhaps).
> > 
> > So far, I haven't found any way of doing this. Search scripts simply  
> > return a float. There doesn't seem to be anything like a "search context"  
> > to decorate the returned results, at least not in the way I need it.
> > 
> > Any other ideas?
> > 
> > Thanks
> > 
> > Klaus
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c6572176-40ee-4532-82ec-e2e210f38803%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c6572176-40ee-4532-82ec-e2e210f38803%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tanguy\_Leroux](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tanguy_leroux/32/121066_2.png) [@Tanguy\_Leroux](https://discuss.elastic.co/u/Tanguy_Leroux)\
**Post date:** [October 3, 2014, 7:31am UTC](https://discuss.elastic.co/t/getting-more-than-just-a-score-out-of-a-search-script/20048/4 "2014-10-03T07:31:40Z")

</div>

You may have a look at the "script\_fields" feature: it allows to return one  
or more script evaluation for each hit (but you can't use the score here).

If you want to compute multiple scores for the same set of results, you can  
try to execute multiple function score queries with a custom  
"script\_score', but I don't see a way to get multiple scores in one query.

-- Tanguy

Le vendredi 3 octobre 2014 08:50:19 UTC+2, Klaus Brunner a écrit :

> Hi Vineeth,
> 
> thanks for the hints, but I'm not sure I understand how this would help. A  
> filter script would allow me to remove documents from the next phase and  
> thus the result set, but there seems to be no way to annotate the results,  
> unless I'm missing something obvious here?
> 
> What I'm really looking for is a way to get more than a float out of  
> scoring (or maybe filtering if that's easier, though it makes more sense in  
> the scoring phase for us). So far we've had to work with some rather  
> "creative" solutions to pack more than a single value into the score, but  
> those are really nasty hacks.
> 
> Klaus
> 
> On Thursday, 2 October 2014 15:39:36 UTC+2, vineeth mohan wrote:
> 
> > Hello Klaus ,
> > 
> > For document flagging or similar feature , you can use script filter with  
> > caching to achieve something close to it -  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html#query-dsl-script-filter)
> > 
> > Also in ES 1.4.0 , there is support for scripted aggregation. Which can  
> > like implement any custom aggregation logic.  
> > Hope these might help in your use case.
> > 
> > Thanks  
> > Vineeth
> > 
> > On Thu, Oct 2, 2014 at 5:06 AM, Klaus Brunner [klaus....@gmail.com](mailto:klaus....@gmail.com)  
> > wrote:
> > 
> > > We're making extensive use of custom scoring (implemented in Java). One  
> > > of the problems we've encountered is that we'd love to get not just the  
> > > score, but other data that result from the score function out of  
> > > Elasticsearch. For example, this could be a flag marking certain documents,  
> > > or some sort of custom score explanation, or even another "score" (if you  
> > > need multiple dimensions perhaps).
> > > 
> > > So far, I haven't found any way of doing this. Search scripts simply  
> > > return a float. There doesn't seem to be anything like a "search context"  
> > > to decorate the returned results, at least not in the way I need it.
> > > 
> > > Any other ideas?
> > > 
> > > Thanks
> > > 
> > > Klaus
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4b889421-e95a-4d12-92f0-971d511bfe39%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4b889421-e95a-4d12-92f0-971d511bfe39%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [October 3, 2014, 4:07pm UTC](https://discuss.elastic.co/t/getting-more-than-just-a-score-out-of-a-search-script/20048/5 "2014-10-03T16:07:21Z")

</div>

Hello Klaus ,

What i had in mind was , whenever you want to see the result with a  
particular flag , apply the filter and see the result. The good thing here  
is the filter result is cached and is not made again and hence you should  
find closer performance.

Thanks  
Vineeth

On Fri, Oct 3, 2014 at 12:20 PM, Klaus Brunner [klaus.brunner@gmail.com](mailto:klaus.brunner@gmail.com)  
wrote:

> Hi Vineeth,
> 
> thanks for the hints, but I'm not sure I understand how this would help. A  
> filter script would allow me to remove documents from the next phase and  
> thus the result set, but there seems to be no way to annotate the results,  
> unless I'm missing something obvious here?
> 
> What I'm really looking for is a way to get more than a float out of  
> scoring (or maybe filtering if that's easier, though it makes more sense in  
> the scoring phase for us). So far we've had to work with some rather  
> "creative" solutions to pack more than a single value into the score, but  
> those are really nasty hacks.
> 
> Klaus
> 
> On Thursday, 2 October 2014 15:39:36 UTC+2, vineeth mohan wrote:
> 
> > Hello Klaus ,
> > 
> > For document flagging or similar feature , you can use script filter with  
> > caching to achieve something close to it - [http://www.elasticsearch.org/](http://www.elasticsearch.org/)  
> > guide/en/elasticsearch/reference/current/query-dsl-  
> > script-filter.html#query-dsl-script-filter
> > 
> > Also in ES 1.4.0 , there is support for scripted aggregation. Which can  
> > like implement any custom aggregation logic.  
> > Hope these might help in your use case.
> > 
> > Thanks  
> > Vineeth
> > 
> > On Thu, Oct 2, 2014 at 5:06 AM, Klaus Brunner [klaus....@gmail.com](mailto:klaus....@gmail.com)  
> > wrote:
> > 
> > > We're making extensive use of custom scoring (implemented in Java). One  
> > > of the problems we've encountered is that we'd love to get not just the  
> > > score, but other data that result from the score function out of  
> > > Elasticsearch. For example, this could be a flag marking certain documents,  
> > > or some sort of custom score explanation, or even another "score" (if you  
> > > need multiple dimensions perhaps).
> > > 
> > > So far, I haven't found any way of doing this. Search scripts simply  
> > > return a float. There doesn't seem to be anything like a "search context"  
> > > to decorate the returned results, at least not in the way I need it.
> > > 
> > > Any other ideas?
> > > 
> > > Thanks
> > > 
> > > Klaus
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/13e8367f-a2e6-4d70-8d7e-3e153200281a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/c6572176-40ee-4532-82ec-e2e210f38803%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c6572176-40ee-4532-82ec-e2e210f38803%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/c6572176-40ee-4532-82ec-e2e210f38803%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c6572176-40ee-4532-82ec-e2e210f38803%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nBLVk-BecM1-nusnvFdMMcsFmtfsYmyykEZ7gY4gv%3D9Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nBLVk-BecM1-nusnvFdMMcsFmtfsYmyykEZ7gY4gv%3D9Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:58am UTC](https://discuss.elastic.co/t/getting-more-than-just-a-score-out-of-a-search-script/20048/6 "2017-07-06T00:58:26Z")

</div>


