Sort script using object fields

Hi !

I have in my mapping a field called "topics" with type "object". Each doc
have one or many fields "topic.t1", "topic.t8" etc, whose value are 0 or 1.
But all docs don't have the same subfields.
Now i'd like to use a script to sort in this kind of way :
"(doc['topic.t1'].value > 0 || doc['topic.t4'].value > 0 ||
doc['topic.t7'].value > 0) ? 1 : 0" DESC

But i saw in the documentation that "the doc notation only allows for
simple valued fields".
So is there another way to do that ?

Thanks in advance for your help.
I hope I clearly exposed my problem, as I'm new to ElasticSearch.

--
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/552491b2-195e-4708-9b3c-1cb6f57d0faa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Up !

Le mardi 24 février 2015 15:52:49 UTC+1, Christophe Rosko a écrit :

Hi !

I have in my mapping a field called "topics" with type "object". Each doc
have one or many fields "topic.t1", "topic.t8" etc, whose value are 0 or 1.
But all docs don't have the same subfields.
Now i'd like to use a script to sort in this kind of way :
"(doc['topic.t1'].value > 0 || doc['topic.t4'].value > 0 ||
doc['topic.t7'].value > 0) ? 1 : 0" DESC

But i saw in the documentation that "the doc notation only allows for
simple valued fields".
So is there another way to do that ?

Thanks in advance for your help.
I hope I clearly exposed my problem, as I'm new to ElasticSearch.

--
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/5f432e67-ddd9-4169-8606-08381adb3e0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

This query should work:

{
"query": {
"function_score": {
"functions": [
{
"script_score": {
"script": "doc['topic.t1'].value > 0 || doc['topic.t4'].value > 0 || doc['topic.t7'].value > 0 ? 1 : 0"
}
}
]
}
}
}

Masaru

On February 26, 2015 at 18:58:38, Christophe Rosko (christophe@digiteka.com) wrote:

Up !

Le mardi 24 février 2015 15:52:49 UTC+1, Christophe Rosko a écrit :

Hi !

I have in my mapping a field called "topics" with type "object". Each doc
have one or many fields "topic.t1", "topic.t8" etc, whose value are 0 or 1.
But all docs don't have the same subfields.
Now i'd like to use a script to sort in this kind of way :
"(doc['topic.t1'].value > 0 || doc['topic.t4'].value > 0 ||
doc['topic.t7'].value > 0) ? 1 : 0" DESC

But i saw in the documentation that "the doc notation only allows for
simple valued fields".
So is there another way to do that ?

Thanks in advance for your help.
I hope I clearly exposed my problem, as I'm new to ElasticSearch.

--
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/5f432e67-ddd9-4169-8606-08381adb3e0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/etPan.54f020c1.2ae8944a.129%40citra.local.
For more options, visit https://groups.google.com/d/optout.