Sorting by values in children objects using a custom score?

I'm trying to sort parent objects by values in the child object by
leveraging the custom score query. I want to sort a title by either asc or
desc. I've attempted to write a simple query to get the custom score
working but for some reason it's always returning a score of "1".

Here is the query I'm attempting:

{
"from" : 0,
"size" : 20,
"query" : {
"has_child" : {
"query" : {
"custom_score" : {
"query" : {
"bool" : {
"must" : [ {
"range" : {
"createDate" : {
"from" : 0,
"to" : null,
"include_lower" : false,
"include_upper" : true
}
}
}, {
"terms" : {
"category" : [ "instrument" ]
}
}]
}
},
"script" : "-doc['sortTitle'].value"
}
},
"child_type" : "com.MyChild"
}
},
"sort" : [ {
"_score" : {
"order" : "asc"
}
} ]
}

Anyone have any ideas on 1) why my score is always 1 which I assume because
my script is totally wrong :wink: and 2) whether there is a more appropriate
way to sort parent objects by values in their children?

I'm using ES 0.20.5

thanks!

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

Presumably your sortTitle field is a string? The script needs to return a
number - you are returning a "negative string".

Clint

On Thursday, 7 March 2013 18:16:14 UTC+1, Grant Gochnauer wrote:

I'm trying to sort parent objects by values in the child object by
leveraging the custom score query. I want to sort a title by either asc or
desc. I've attempted to write a simple query to get the custom score
working but for some reason it's always returning a score of "1".

Here is the query I'm attempting:

{
"from" : 0,
"size" : 20,
"query" : {
"has_child" : {
"query" : {
"custom_score" : {
"query" : {
"bool" : {
"must" : [ {
"range" : {
"createDate" : {
"from" : 0,
"to" : null,
"include_lower" : false,
"include_upper" : true
}
}
}, {
"terms" : {
"category" : [ "instrument" ]
}
}]
}
},
"script" : "-doc['sortTitle'].value"
}
},
"child_type" : "com.MyChild"
}
},
"sort" : [ {
"_score" : {
"order" : "asc"
}
} ]
}

Anyone have any ideas on 1) why my score is always 1 which I assume
because my script is totally wrong :wink: and 2) whether there is a more
appropriate way to sort parent objects by values in their children?

I'm using ES 0.20.5

thanks!

--
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 Clint,

Thanks - I assumed as much but am trying to figure out how I can calculate
a numerical value that I could leverage to sort a list by alpha order via
script. I didn't see any functions in ES that may provide this so it may be
that it's not possible. Any thoughts?

Thanks!

On Fri, Mar 8, 2013 at 6:31 AM, Clinton Gormley clint@traveljury.comwrote:

Hi Grant

Presumably your sortTitle field is a string? The script needs to return a
number - you are returning a "negative string".

Clint

On Thursday, 7 March 2013 18:16:14 UTC+1, Grant Gochnauer wrote:

I'm trying to sort parent objects by values in the child object by
leveraging the custom score query. I want to sort a title by either asc or
desc. I've attempted to write a simple query to get the custom score
working but for some reason it's always returning a score of "1".

Here is the query I'm attempting:

{
"from" : 0,
"size" : 20,
"query" : {
"has_child" : {
"query" : {
"custom_score" : {
"query" : {
"bool" : {
"must" : [ {
"range" : {
"createDate" : {
"from" : 0,
"to" : null,
"include_lower" : false,
"include_upper" : true
}
}
}, {
"terms" : {
"category" : [ "instrument" ]
}
}]
}
},
"script" : "-doc['sortTitle'].value"
}
},
"child_type" : "com.MyChild"
}
},
"sort" : [ {
"_score" : {
"order" : "asc"
}
} ]
}

Anyone have any ideas on 1) why my score is always 1 which I assume
because my script is totally wrong :wink: and 2) whether there is a more
appropriate way to sort parent objects by values in their children?

I'm using ES 0.20.5

thanks!

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/KMmEOuc9Ce0/unsubscribe?hl=en-US
.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Grant Gochnauer | Vodori Inc | grant.gochnauer@vodori.com | (w)
312.324.0124 | (c) 312.504.5004

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