-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting based on parent/child relationship #2917
Comments
@kul At the moment this isn't possible. This feature will be added in the near future. For now you use @clintongormley's excellent workaround: http://stackoverflow.com/questions/14504180/elasticsearch-sorting-parents-through-child-values/14519947#14519947 This workaround allows you to sort on child values by using |
oh wow! if i can specify a query, it mean limitless possibilities for sorting using nested has_child/has_parent clause. Thanks |
Really looking forward to this feature - we use parent/child relationships extensively and right now have to copy children values on parent object to sort on them. Will give the work-around a try but hopefully we'll see this in the .90 series too ;) Thank you! |
Is it true that the work-around requires you to leveraged nested mappings instead of a true/parent child relationship for the sorting to work? thanks! |
On 5/14/2013 10:52 AM, Grant Gochnauer wrote:
http://www.elasticsearch.org/guide/reference/query-dsl/has-child-query/ Without having seen Clinton's post, but having discussed it a bit on the The problem that a score is a Float, so you can have round off problems If the score was a double I would be able use ~16 (base 10) digits of -Paul |
Thanks for the reply P-Hill... We are developing an API that allows for an arbitrary sort on child fields which are different depending on who is leveraging our API. In other words, without built in support for sorting on child document fields, we aren't able to use the custom score very well. Thanks |
+2 On 5/15/2013 6:24 AM, Grant Gochnauer wrote:
|
+1 |
Very important feature since it's computationally hard to update thousands of documents when all you need is update only one field in a big document and than make sorting by this field. For example contacts which have property like last contacted which changes very frequently but not whole contact. Update api doesn't solve my case since enabling _source will increase my index a lot. |
+1 |
+1 Hope to see this natively supported in ES! |
though the memory signature it leaves and the cost of compute is slightly high, this will be one of the most used feature if it comes out in ES. Eagerly looking forward to it! |
+10 |
+1 IMHO, it's definitely one the top missing feature, along with:
|
Are there any plans to support this feature in the foreseeable future? |
Once the refactoring in #8134 is in, this is planned to be added. Like with the current refactoring the sorting by child or parent field should be added to the new Lucene query time join first. |
This is very exciting. Is there a plan of integrating this in an upcoming release, now that #8134 is solved? |
@kul @martijnvg @clintongormley How do I do the workaround mentioned in http://stackoverflow.com/questions/14504180/elasticsearch-sorting-by-nested-documents-values/14519947#14519947 for a parent child relationship? In my script field what should replace "doc['locations.order'].value" to refer to the child document's field? Thanks in advance |
would really like to see this implemented |
@martijnvg With #8134 in, do you see a way forward for implementing this? |
@clintongormley Yes, I do see a way how this can be implemented. Similar to how the join is implemented, but instead of aggregating child scores per parent the sorting should aggregate sort values instead. |
+1 For now, In my situation (sorting by parent.field), I'm working with function_score.
|
I don't think we can realistically make it work so I am closing it as a won't fix. When this is needed, a possible workaround is to fold sort values into the score as shown by @danipl in the above message. |
@jpountz What has changed? I thought @martijnvg said he saw a way forward? |
This is something that could be implemented, but it would require a lot of specialization depending on the types of the fields that are being sorted, and I don't think that would be sustainable in the long term. Moreover, I am concerned about making features that do not scale more appealing (parent/child needs to perform a linear scan in the 2nd phase of its execution in the general case). |
@rpedela I did and still see a way how this could be implemented. Implementing this feature does require writing quite some code that will only be used when using has_child/has_parent queries and sorting by a field, which won't be used if sorting by _score or when other queries are used. Over time I did see that the workaround provided here is sufficient for most people wanting to sort based on a field in a child document or parent document. I think closing this issue as won't fix is jusitfied, since adding this is far from trivial and most of the time the workaround is good enough |
Fair enough. Could small but complete examples (sort by parent and sort by child) be added to the docs showing how to sort using the workaround? I think without official documentation this will keep coming up based on the amount of interest. |
Yes! |
I there any possibility to use this workaround to sort on text field? |
@sop3k I can't think of any normal way to make it work on a string field, but I came up with a method which may or may not work for you depending on your application and tooling. At index time, convert the string you want to sort into a 63-bit number and index it alongside the string field as a I haven't actually tried the above, but it seems likely to work if you're staying in the ASCII range of characters. Of course, this would not work well with UTF8, and would probably not provide enough accuracy to be useful with UTF16. |
Thank @dimfeld for comment. I was thinking about same solution but as you mentoin it's very limited to do so with UTF8 and UTF16. |
Hi, any updates for the workaround? |
@lonre The workaround has been described here: https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-has-child-query.html#_sorting and here: |
@martijnvg Does the workaround above work for String fields? |
+1 |
2 similar comments
+1 |
+1 |
+1 |
1 similar comment
+1 |
Also need workaround for strings |
+1 |
I haven't been able to get this workaround to work well with a number field that can have a wide range of negative, positive, and missing values. This is due to the limited precision of |
+1 for this feature to be added |
+1 need this feature for string sorting |
+1 |
2 similar comments
+1 |
+1 |
Currently there is no way to sort documents based on parent child relation. E.g.
Sorting a doc based on child doc field or the opposite.
The text was updated successfully, but these errors were encountered: