Skip to content

Commit a3a8a15

Browse files
committed
Flip order of ignored and non ignored values in keyword field
1 parent 09fa103 commit a3a8a15

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

test/framework/src/main/java/org/elasticsearch/index/mapper/KeywordFieldSyntheticSourceSupport.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public boolean preservesExactSource() {
4949

5050
@Override
5151
public MapperTestCase.SyntheticSourceExample example(int maxValues) {
52-
return example(maxValues, false);
52+
return example(maxValues, false, false);
5353
}
5454

55-
public MapperTestCase.SyntheticSourceExample example(int maxValues, boolean loadBlockFromSource) {
55+
public MapperTestCase.SyntheticSourceExample example(int maxValues, boolean loadBlockFromSource, boolean flipOrder) {
5656
if (ESTestCase.randomBoolean()) {
5757
Tuple<String, String> v = generateValue();
5858
Object sourceValue = preservesExactSource() ? v.v1() : v.v2();
@@ -77,7 +77,11 @@ public MapperTestCase.SyntheticSourceExample example(int maxValues, boolean load
7777
out = in;
7878
} else {
7979
var validValuesInCorrectOrder = store ? validValues : outputFromDocValues;
80-
var syntheticSourceOutputList = Stream.concat(validValuesInCorrectOrder.stream(), ignoredValues.stream()).toList();
80+
// this is an ugly little hack that flips the order of ignored values, which is important for the text-family fields where the
81+
// ordering of produced synthetic source values can be different from what was supplied
82+
var syntheticSourceOutputList = flipOrder
83+
? Stream.concat(ignoredValues.stream(), validValuesInCorrectOrder.stream()).toList()
84+
: Stream.concat(validValuesInCorrectOrder.stream(), ignoredValues.stream()).toList();
8185
out = syntheticSourceOutputList.size() == 1 ? syntheticSourceOutputList.get(0) : syntheticSourceOutputList;
8286
}
8387

test/framework/src/main/java/org/elasticsearch/index/mapper/TextFieldFamilySyntheticSourceTestSetup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public MapperTestCase.SyntheticSourceExample example(int maxValues) {
8181
// Block loader will not use keyword multi-field if it has ignore_above configured.
8282
// And in this case it will use values from source.
8383
boolean loadingFromSource = ignoreAbove != null;
84-
MapperTestCase.SyntheticSourceExample delegate = keywordMultiFieldSyntheticSourceSupport.example(maxValues, loadingFromSource);
84+
MapperTestCase.SyntheticSourceExample delegate = keywordMultiFieldSyntheticSourceSupport.example(maxValues, loadingFromSource, true);
8585

8686
return new MapperTestCase.SyntheticSourceExample(delegate.inputValue(), delegate.expectedForSyntheticSource(), b -> {
8787
b.field("type", fieldType);

0 commit comments

Comments
 (0)