Skip to content
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

Sort ASC by a field should give those results without that field value #31106

Open
nehajatav opened this issue May 3, 2024 · 7 comments
Open
Assignees
Projects
Milestone

Comments

@nehajatav
Copy link

Describe the bug
Currently none of sort ascending and sort descending are giving the right result

To Reproduce
Add doc1 with field f1 as a,
add doc2 with field f1 as b,
add doc3 with field f1 missing

Expected behavior
Ascending should give order
doc3,doc1, doc2

@baldersheim
Copy link
Member

baldersheim commented May 3, 2024

You have to provide the schema definition, 3 documents and the query and the result you get.
This is ancient functionality that see extensive use, so you must provide something reproducible.
If the value is missing behavior depends on type of field.
Fx for strings, if the field is not set set it will be treated as an empty string.

@nehajatav
Copy link
Author

nehajatav commented May 8, 2024

What is the behaviour if the field is of type long and some docs are missing that field?

@bjormel
Copy link
Member

bjormel commented May 9, 2024

If the field is unset for a document, the sort value for that document will be lower than the value for any other document with a value set.
See Quick Start, using Docker, for an easy way to experiment with Vespa at a small scale.

If you need another behaviour you can use a document processor to set a value when it is missing when ingesting data.
See Fields

A field can not be defined with a default value. Use a document processor to assign a default to document put/update operations.

@baldersheim
Copy link
Member

Correct, if you sort ascending unset document will come first, descending it will come last.

@baldersheim
Copy link
Member

This is not something that we can change without a major version, and it is not clear what is correct either.

@baldersheim
Copy link
Member

Or is it ? @bratseth could we change this so sorting on unset values always sorted last, similar to what we do for NaN rank ?

@bratseth
Copy link
Member

bratseth commented May 9, 2024

I would say people shouldn't reasonably depend on this.
But that said, lots of people ask for ways to find documents with an unset value of some field. We have never told them about this way of doing it (as far as I know), but maybe some found it by themselves?

@frodelu frodelu assigned toregge and unassigned baldersheim May 15, 2024
@frodelu frodelu added this to the soon milestone May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Support
Awaiting triage
Development

No branches or pull requests

6 participants