Sorting and scripting

I have quite a few doubts about sorting and scripting.

I installed the Python plugin for ES, and as far as I understood I can
run arbitraty Python code there, right?

I have some documents which contain list of ideas, and for example I
want to sort on the length of this array.

So I write the sort dictionary in this way:

script = {
'script': "len(doc['ideas'])",
'lang': 'python',
'order': 'asc',
}
sort = {'sort': {'_script': script}}

One surprising thing is that even if I put something that makes no
sense in "script" (ln(doc['ideas']) for example) elasticsearch doesn't
complain at all...

Is that normal?

I also couldn't find much documentation/examples about how to use the
scripting, do you know some other resources?

Thanks,
Andrea

--

I suspect that sort order is not applied correctly. Otherwise, it would
have complained about absence of "type" parameter and invalid argument for
len. Try this:

curl "localhost:9200/your-index/your-type/_search" -d '{
"sort": [
{
"_script": {
"script" : "len(doc["ideas"].values)",
"type" : "number",
"lang": "python"
}
}
]
}'

to see if it works with your data from command line.

On Tuesday, January 22, 2013 1:13:38 PM UTC-5, andrea crotti wrote:

I have quite a few doubts about sorting and scripting.

I installed the Python plugin for ES, and as far as I understood I can
run arbitraty Python code there, right?

I have some documents which contain list of ideas, and for example I
want to sort on the length of this array.

So I write the sort dictionary in this way:

script = {
'script': "len(doc['ideas'])",
'lang': 'python',
'order': 'asc',
}
sort = {'sort': {'_script': script}}

One surprising thing is that even if I put something that makes no
sense in "script" (ln(doc['ideas']) for example) elasticsearch doesn't
complain at all...

Is that normal?

I also couldn't find much documentation/examples about how to use the
scripting, do you know some other resources?

Thanks,
Andrea

--
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.