Questions RE: ES Script Written in JavaScript

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.

     "things": {
         "type": "nested",
         "properties": {
             "thing_id": {
                 "type": "long"
             },
             "count": {
                 "type": "long"
             },
             "sentiment": {
                 "type": "double"
             }
         }
     },
    

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a0dd710c-0c45-49d1-9224-d46336997f51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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.

     "things": {
         "type": "nested",
         "properties": {
             "thing_id": {
                 "type": "long"
             },
             "count": {
                 "type": "long"
             },
             "sentiment": {
                 "type": "double"
             }
         }
     },
    

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1b0ef9ea-f17d-451c-8849-4b4c52388257%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.