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
Scroll search with ASC sort order on missing fields does not terminate #9136
Comments
Nice catch! thanks @gokl |
@martijnvg could you have a look at this please? |
This is related to #9155. When sorting missing values last on a string field, we artificially replace diff --git a/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/BytesRefFieldComparatorSource.java b/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/BytesRefFieldComparatorSource.java
index 7e64720..66fa306 100644
--- a/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/BytesRefFieldComparatorSource.java
+++ b/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/BytesRefFieldComparatorSource.java
@@ -97,11 +97,21 @@ public class BytesRefFieldComparatorSource extends IndexFieldData.XFieldComparat
// TopDocs.merge deal with it (it knows how to)
BytesRef value = super.value(slot);
if (value == null) {
+ assert sortMissingFirst(missingValue) || sortMissingLast(missingValue);
value = missingBytes;
}
return value;
}
+ public void setTopValue(BytesRef topValue) {
+ // symetric of value(int): if we need to feed the comparator with <tt>null</tt>
+ // if we overrode the value with MAX_TERM in value(int)
+ if (topValue == missingBytes && (sortMissingFirst(missingValue) || sortMissingLast(missingValue))) {
+ topValue = null;
+ }
+ super.setTopValue(topValue);
+ }
+
};
} But I hope we can come with a cleaner solution on 2.x by doing #9155 |
@jpountz This proposed fix fixes the reported bug, so +1 for adding this initially to master, 1.x and 1.4 branches and then work on a better fix in master. |
For the comparator to work correctly, we need to give it the same value in `setTopValue` as the value that it gave back in `value`. Close elastic#9136
For the comparator to work correctly, we need to give it the same value in `setTopValue` as the value that it gave back in `value`. Close #9136
For the comparator to work correctly, we need to give it the same value in `setTopValue` as the value that it gave back in `value`. Close #9136
For the comparator to work correctly, we need to give it the same value in `setTopValue` as the value that it gave back in `value`. Close elastic#9136
Hi,
doing an ASC sorted scroll search on a field that only exists in the mapping but not in the document yields to a non terminating scroll. It always returns the documents that don't have the field on which we sorted.
Both _search/scroll requests should not return documents because the initial search already returned the document with id 1, but they do return the document.
However, using either a DESC sort order or "missing":"_first" makes the scroll work/terminate as expected.
The text was updated successfully, but these errors were encountered: