Sorting by an nested object field

Hi all!

I have an nested mapping and data like the one in this example:
http://www.elasticsearch.org/guide/reference/mapping/nested-type.html
This works great when I'm using a nested filter or nested query.

{
"obj1" : [
{
"name" : "blue",
"count" : 4
},
{
"name" : "green",
"count" : 6
}
]
}
[Snippet is copied from http://www.elasticsearch.org/guide/reference/mapping/nested-type.html]

Now I'm trying to sort after on one the fields in the nested object
but having problems how to solve this problem.
So, how would you guys try to sort based on value of "count" in the
example above?

Thanks in advance,
Patrik

1 Like

You can't sort on nest fields, moreover, since they are multi valued, even
if they were in the "root" object, you can't sort on them.

On Fri, Dec 16, 2011 at 12:13 AM, Patrik Johansson <
patrik.j.johansson@kentor.se> wrote:

Hi all!

I have an nested mapping and data like the one in this example:
Elasticsearch Platform โ€” Find real-time answers at scale | Elastic
This works great when I'm using a nested filter or nested query.

{
"obj1" : [
{
"name" : "blue",
"count" : 4
},
{
"name" : "green",
"count" : 6
}
]
}
[Snippet is copied from
Elasticsearch Platform โ€” Find real-time answers at scale | Elastic]

Now I'm trying to sort after on one the fields in the nested object
but having problems how to solve this problem.
So, how would you guys try to sort based on value of "count" in the
example above?

Thanks in advance,
Patrik

Thanks for the reply!

So if pure sorting on nest fields is a no-go, is it possible to do some kind of
boosting or custom_score based of the value (or boost) for the nest fields?

//Patrik J

16 dec 2011 kl. 16.47 skrev Shay Banon:

You can't sort on nest fields, moreover, since they are multi valued, even if they were in the "root" object, you can't sort on them.

On Fri, Dec 16, 2011 at 12:13 AM, Patrik Johansson <patrik.j.johansson@kentor.semailto:patrik.j.johansson@kentor.se> wrote:
Hi all!

I have an nested mapping and data like the one in this example:
http://www.elasticsearch.org/guide/reference/mapping/nested-type.html
This works great when I'm using a nested filter or nested query.

{
"obj1" : [
{
"name" : "blue",
"count" : 4
},
{
"name" : "green",
"count" : 6
}
]
}
[Snippet is copied from http://www.elasticsearch.org/guide/reference/mapping/nested-type.html]

Now I'm trying to sort after on one the fields in the nested object
but having problems how to solve this problem.
So, how would you guys try to sort based on value of "count" in the
example above?

Thanks in advance,
Patrik

You can, but "within" the nested query per nested element, but check if its
fast enough for you.

On Mon, Dec 19, 2011 at 10:16 AM, Patrik Johansson <
patrik.j.johansson@kentor.se> wrote:

Thanks for the reply!

So if pure sorting on nest fields is a no-go, is it possible to do some
kind of
boosting or custom_score based of the value (or boost) for the nest fields?

//Patrik J

16 dec 2011 kl. 16.47 skrev Shay Banon:

You can't sort on nest fields, moreover, since they are multi valued, even
if they were in the "root" object, you can't sort on them.

On Fri, Dec 16, 2011 at 12:13 AM, Patrik Johansson <
patrik.j.johansson@kentor.se> wrote:

Hi all!

I have an nested mapping and data like the one in this example:
Elasticsearch Platform โ€” Find real-time answers at scale | Elastic
This works great when I'm using a nested filter or nested query.

{
"obj1" : [
{
"name" : "blue",
"count" : 4
},
{
"name" : "green",
"count" : 6
}
]
}
[Snippet is copied from
Elasticsearch Platform โ€” Find real-time answers at scale | Elastic]

Now I'm trying to sort after on one the fields in the nested object
but having problems how to solve this problem.
So, how would you guys try to sort based on value of "count" in the
example above?

Thanks in advance,
Patrik

In case you're still working on this problem, support for sorting by fields
inside of nested documents was added in 0.90:

On Thursday, 15 December 2011 17:13:37 UTC-5, Patrik Johansson wrote:

Hi all!

I have an nested mapping and data like the one in this example:
Elasticsearch Platform โ€” Find real-time answers at scale | Elastic
This works great when I'm using a nested filter or nested query.

{
"obj1" : [
{
"name" : "blue",
"count" : 4
},
{
"name" : "green",
"count" : 6
}
]
}
[Snippet is copied from
Elasticsearch Platform โ€” Find real-time answers at scale | Elastic]

Now I'm trying to sort after on one the fields in the nested object
but having problems how to solve this problem.
So, how would you guys try to sort based on value of "count" in the
example above?

Thanks in advance,
Patrik

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

That's what I thought, but I can't get it working
(see Redirecting to Google Groups).
Can someone provide a working example?

On Wednesday, 22 May 2013 20:24:27 UTC+2, Dane Bertram wrote:

In case you're still working on this problem, support for sorting by
fields inside of nested documents was added in 0.90:

Add support for sorting by fields inside one or more nested objects ยท Issue #2662 ยท elastic/elasticsearch ยท GitHub

On Thursday, 15 December 2011 17:13:37 UTC-5, Patrik Johansson wrote:

Hi all!

I have an nested mapping and data like the one in this example:
Elasticsearch Platform โ€” Find real-time answers at scale | Elastic
This works great when I'm using a nested filter or nested query.

{
"obj1" : [
{
"name" : "blue",
"count" : 4
},
{
"name" : "green",
"count" : 6
}
]
}
[Snippet is copied from
Elasticsearch Platform โ€” Find real-time answers at scale | Elastic]

Now I'm trying to sort after on one the fields in the nested object
but having problems how to solve this problem.
So, how would you guys try to sort based on value of "count" in the
example above?

Thanks in advance,
Patrik

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