-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Allow Ids query to score documents by ids order #3458
Comments
If the problem is having consistent ordering of your documents and you only have the ids filter (or query), I'd suggest to switch to the multi_get api. In that case you would get back the documents in the same order you have put the id in your request. Also, get and multi_get are a better fit when using elasticsearch as a storage as they are real-time, while search is only (Near) real-time, which means that a refresh needs to happen in order to make newly indexed documents searchable (a refresh happens automatically every second by default though). Otherwise, if you do need a query and want to use the search API, can't you just sort your documents by Let me know if this helps and maybe next time (if you haven't done it yet) can you send a question to the mailing list just to double check that you tried all the options you have? |
Thank for the reply :)
PS: Here is the related discussion in the ES ML: https://groups.google.com/d/topic/elasticsearch/QQ8RXyMD4fM/discussion |
Thanks for your quick feeback, I see what you mean! I think a custom script is the way to go here, as it's really your own logic and not something really common. I'd suggest to have a look at script sorting though. In fact, you need to infuence the way the score is computed because you are sorting by score, but if you are able to express your sorting logic as a script, you can just sort based on it, that's it. |
That's exactly what I do (see the second example in my issue); |
Got it, what I suggested to do is different to custom_score, although still executes a script per document. Have a look at script sorting. |
I'd love to have a |
Unfortunately by some reason function Maybe someone else knows how to get this feature to work again? |
Actually i just tried using
|
My script just looks like this: |
Closing as won't fix. |
I would still consider supporting an alternative for this, @clintongormley It's pity that after 3 years ES haven't provide a reliable alternative for these situations where we need to keep the order of the documents that have been requested + apply search filters. Scripting is not an option for serious and large-scale applications and anyway we cannot use It would be enough to be able to sort by position in an array of values, provided in the ES request, like:
Similar to the way
If you reconsider it, I could open this in a new feature-request ticket. |
I suggest you use a script like this : |
I see the feature request closed. Is there a support in 6.4+? We need to sort index of 20k+ documents (with ids as strings - guids) and dont think that script with custom ranking is the correct way to do this... |
The original request to support through query option in json is still useful instead of maintaining the scripting logic. Can you please consider this feature request? |
sort by script will take more times |
This is more a feature suggestion than an issue.
Id's query are great and allow to use ES as a great searchable datastore.
I have some use cases where I want to restrict user search to a limited set of documents - so I use Ids query with some match queries.
But sometime, I don't have query, I just want my N documents, without sorting on a field: and in this case, all my documents get a score of 1.
If I run this query multiple times, I get different order almost everytime, as score are equals.
This is not great for users (as they get a random feeling), and I may also want to use the id values order as document order. So I created a custom script query for this case:
As you can see, I inject the ids to the script as a param, and give them a custom score based on the position of the current document ID in the list.
This fix consistency and ordering issues, but this is slow when dealing with lots of ID's (started noticing when hitting 3k ids).
What I was thinking about is some kind of option we can add to IdsQuery to score docs based on the Id position.
With this value to "true", the IdsQuery could give a score to each document, removing the random effect and the need of a custom script to sort by id's.
What do you think?!
Thanks!
The text was updated successfully, but these errors were encountered: