# Questions RE: ES Script Written in JavaScript

**URL:** <https://discuss.elastic.co/t/questions-re-es-script-written-in-javascript/18798>\
**Category:** Elasticsearch\
**Created:** [July 22, 2014, 4:17pm UTC](https://discuss.elastic.co/t/questions-re-es-script-written-in-javascript/18798 "2014-07-22T16:17:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roland\_Dunn](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Roland\_Dunn](https://discuss.elastic.co/u/Roland_Dunn)\
**Post date:** [July 22, 2014, 4:17pm UTC](https://discuss.elastic.co/t/questions-re-es-script-written-in-javascript/18798/1 "2014-07-22T16:17:40Z")

</div>

Hi,  
Wonder if anyone could help. I've managed to get a query script up and  
running, using JavaScript. The script resides in  
/etc/elasticsearch/scripts.

I'm using a function\_score query as follows:

```
    "function_score": {
      "query": {
        "match_all": {}
      },
      "script_score": {
        "script": "poot",
        "params": {
          "topics_dict_param": {
            "4": 102
          }
        }
      }

```

I'm passing into the JS script a dictionary of values.

Questions:

1. What determines the "return value" of the JS script? At the moment I  
just have "retscore;" as a standalone line in the script, this seems to  
work, but feels bit random. Would like something more explicit.

2. How can I debug the JS script? Can I output some values somewhere? E.g.  
print, or log? If so, where does the output go?

3. The mapping of the ES index involves an array of nested objects e.g.

Can I access this via \_source.things? And if I can, can I do something like  
\_source.things[0].thing\_id ?

Any help v welcome.

Thanks,  
R

--  
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/a0dd710c-0c45-49d1-9224-d46336997f51%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a0dd710c-0c45-49d1-9224-d46336997f51%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Roland\_Dunn](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Roland\_Dunn](https://discuss.elastic.co/u/Roland_Dunn)\
**Post date:** [July 23, 2014, 10:44am UTC](https://discuss.elastic.co/t/questions-re-es-script-written-in-javascript/18798/2 "2014-07-23T10:44:05Z")

</div>

OK, answering a couple of my own questions:

1. Return value: \_score e.g.

\_score = Math.sqrt(retscore);

1. Accessing nested: easy enough:  
\_source.things[i]

2. Debugging. Dunno.

On Tuesday, 22 July 2014 17:17:40 UTC+1, Roland Dunn wrote:

> Hi,  
> Wonder if anyone could help. I've managed to get a query script up and  
> running, using JavaScript. The script resides in  
> /etc/elasticsearch/scripts.
> 
> I'm using a function\_score query as follows:
> 
> ```
> "function_score": {
> "query": {
> "match_all": {}
> },
> "script_score": {
> "script": "poot",
> "params": {
> "topics_dict_param": {
> "4": 102
> }
> }
> }
> 
> ```
> 
> I'm passing into the JS script a dictionary of values.
> 
> Questions:
> 
> 1. What determines the "return value" of the JS script? At the moment I  
> just have "retscore;" as a standalone line in the script, this seems to  
> work, but feels bit random. Would like something more explicit.
> 
> 2. How can I debug the JS script? Can I output some values somewhere? E.g.  
> print, or log? If so, where does the output go?
> 
> 3. The mapping of the ES index involves an array of nested objects e.g.
> 
> Can I access this via \_source.things? And if I can, can I do something  
> like \_source.things[0].thing\_id ?
> 
> Any help v welcome.
> 
> Thanks,  
> R

--  
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/1b0ef9ea-f17d-451c-8849-4b4c52388257%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1b0ef9ea-f17d-451c-8849-4b4c52388257%40googlegroups.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, 1:13am UTC](https://discuss.elastic.co/t/questions-re-es-script-written-in-javascript/18798/3 "2017-07-06T01:13:59Z")

</div>


