Server-side ("preloaded") script return value

I have a query that calls a python script. That part is working finally,
which is confirmed by the script's output to a log file.

Now, I need to get the value back to the query, but I only ever see
"my_field" : null
in the response.

How am I supposed to return the value from the script to the query? I'm
currently sending it back on stdout.

    "script_fields" : {
                    "my_field": {
                            "script": "testscript",
                            "params": {
                                    "field": "value1",
                                    "tag" : "value2"
                            },
                            "type": "float",
                            "lang": "python"
                    }
    }

But the response is always:

{
"_index" : "logstash-2013.11.01",
"_type" : "app",
"_id" : "rV5JRvZySaS6gwdT6pPvyw",
"_score" : 0.36469176, "_source" : {...},
"fields" : {
"my_field" : null
}
}

The end of the python script:

sys.stdout.write(ret)
sys.stdout.write("\n")
sys.stdout.flush()

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,
script fields are meant to create on-the-fly new fields which can be
returned for each document that matches a query. Can you elaborate on why
you need to send the result of the script back to the query?

On Friday, November 1, 2013 5:36:45 PM UTC+1, rastro wrote:

I have a query that calls a python script. That part is working finally,
which is confirmed by the script's output to a log file.

Now, I need to get the value back to the query, but I only ever see
"my_field" : null
in the response.

How am I supposed to return the value from the script to the query? I'm
currently sending it back on stdout.

    "script_fields" : {
                    "my_field": {
                            "script": "testscript",
                            "params": {
                                    "field": "value1",
                                    "tag" : "value2"
                            },
                            "type": "float",
                            "lang": "python"
                    }
    }

But the response is always:

{
"_index" : "logstash-2013.11.01",
"_type" : "app",
"_id" : "rV5JRvZySaS6gwdT6pPvyw",
"_score" : 0.36469176, "_source" : {...},
"fields" : {
"my_field" : null
}
}

The end of the python script:

sys.stdout.write(ret)
sys.stdout.write("\n")
sys.stdout.flush()

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Luca pointed out that ES calls python with an 'eval', so multi-line scripts
won't work on the server side, either. There's some info in this jython
ticket:

      http://bugs.jython.org/issue1713 .

I switched to javascript and am able to get the field back for facets and
script_fields.

Thanks, Luca.

On Monday, November 4, 2013 9:41:06 AM UTC-8, Luca Cavanna wrote:

Hi,
script fields are meant to create on-the-fly new fields which can be
returned for each document that matches a query. Can you elaborate on why
you need to send the result of the script back to the query?

On Friday, November 1, 2013 5:36:45 PM UTC+1, rastro wrote:

I have a query that calls a python script. That part is working finally,
which is confirmed by the script's output to a log file.

Now, I need to get the value back to the query, but I only ever see
"my_field" : null
in the response.

How am I supposed to return the value from the script to the query? I'm
currently sending it back on stdout.

    "script_fields" : {
                    "my_field": {
                            "script": "testscript",
                            "params": {
                                    "field": "value1",
                                    "tag" : "value2"
                            },
                            "type": "float",
                            "lang": "python"
                    }
    }

But the response is always:

{
"_index" : "logstash-2013.11.01",
"_type" : "app",
"_id" : "rV5JRvZySaS6gwdT6pPvyw",
"_score" : 0.36469176, "_source" : {...},
"fields" : {
"my_field" : null
}
}

The end of the python script:

sys.stdout.write(ret)
sys.stdout.write("\n")
sys.stdout.flush()

--
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.
For more options, visit https://groups.google.com/groups/opt_out.