# Return multiple values from script engine plugin

**URL:** <https://discuss.elastic.co/t/return-multiple-values-from-script-engine-plugin/127390>\
**Category:** Elasticsearch\
**Created:** [April 9, 2018, 9:45pm UTC](https://discuss.elastic.co/t/return-multiple-values-from-script-engine-plugin/127390 "2018-04-09T21:45:52Z")\
**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 9, 2018, 9:45pm UTC](https://discuss.elastic.co/t/return-multiple-values-from-script-engine-plugin/127390/1 "2018-04-09T21:45:52Z")

</div>

ES 6.2.3

My index contains docs like this:  
{  
str1: "some string",  
str2: "other string"  
}

I'm using a custom plugin that implements a ScriptEngine based on these examples:  
[Advanced scripts using script engines](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-engine.html)  
[ExplainableScript integration test](https://github.com/elastic/elasticsearch/blob/v6.2.3/server/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java)

I can pass in parameters, compare them to doc values, and return a score.  
So far, so good!

Here's the hard part. I need to return more than just the double score. I need to get this information back for each document matched:  
{  
fuzzyQuality\_str1: "high", // or an int or double, doesn't matter  
fuzzyQuality\_str2: "low", // or an int or double, doesn't matter  
composite\_score: 42.0  
}

I can do the fuzzy computations, and use them to calculate a composite score, and even return that score. I just can't figure out how to also get the "fuzzy quality" values back too.

Is there a way to modify the "hit" somehow?  
Or can I return a vector of values?  
Some other way?

---

<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 9, 2018, 10:58pm UTC](https://discuss.elastic.co/t/return-multiple-values-from-script-engine-plugin/127390/2 "2018-04-09T22:58:17Z")

</div>

Unfortunately there is no way to do this. You can, however, use [script fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html). These would be separate executions (and different scripts), but the script fields will only run on the top N documents, so the overhead should be minimal compared to the cost of scoring millions of documents.

---

<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 10, 2018, 1:11pm UTC](https://discuss.elastic.co/t/return-multiple-values-from-script-engine-plugin/127390/3 "2018-04-10T13:11:32Z")

</div>

Thank you Ryan - appreciate your quick response.

---

<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 8, 2018, 1:11pm UTC](https://discuss.elastic.co/t/return-multiple-values-from-script-engine-plugin/127390/4 "2018-05-08T13:11:54Z")

</div>

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