Skip to content

Commit 91ea2ad

Browse files
committed
Fix multivalued fields
1 parent 05a2dce commit 91ea2ad

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

server/src/main/java/org/elasticsearch/index/mapper/BinaryDocValuesSyntheticFieldLoaderLayer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717

1818
import java.io.IOException;
1919

20-
public abstract class BinaryDocValuesSyntheticFieldLoaderLayer implements CompositeSyntheticFieldLoader.DocValuesLayer {
20+
public final class BinaryDocValuesSyntheticFieldLoaderLayer implements CompositeSyntheticFieldLoader.DocValuesLayer {
2121

2222
private final String name;
2323
private SortedBinaryDocValues bytesValues;
2424
private boolean hasValue;
2525

26-
protected BinaryDocValuesSyntheticFieldLoaderLayer(String name) {
26+
public BinaryDocValuesSyntheticFieldLoaderLayer(String name) {
2727
this.name = name;
2828
}
2929

30-
protected abstract void writeValue(XContentBuilder b, BytesRef value) throws IOException;
31-
3230
@Override
3331
public long valueCount() {
3432
return bytesValues == null ? 0 : bytesValues.docValueCount();
@@ -61,7 +59,10 @@ public void write(XContentBuilder b) throws IOException {
6159
return;
6260
}
6361

64-
writeValue(b, bytesValues.nextValue());
62+
for (int i = 0; i < bytesValues.docValueCount(); ++i) {
63+
BytesRef value = bytesValues.nextValue();
64+
b.utf8Value(value.bytes, value.offset, value.length);
65+
}
6566
}
6667

6768
@Override

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,25 +1497,15 @@ protected BytesRef preserve(BytesRef value) {
14971497
} else {
14981498
assert offsetsFieldName == null;
14991499
assert indexSettings.sourceKeepMode() == SourceKeepMode.NONE;
1500-
layers.add(new BinaryDocValuesSyntheticFieldLoaderLayer(fieldType().binaryDocValuesName()) {
1501-
@Override
1502-
protected void writeValue(XContentBuilder b, BytesRef value) throws IOException {
1503-
b.utf8Value(value.bytes, value.offset, value.length);
1504-
}
1505-
});
1500+
layers.add(new BinaryDocValuesSyntheticFieldLoaderLayer(fieldType().binaryDocValuesName()));
15061501
}
15071502
}
15081503

15091504
// if ignore_above is set, then there is a chance that this field will be ignored. In such cases, we save an
15101505
// extra copy of the field for supporting synthetic source. This layer will check that copy.
15111506
if (fieldType().ignoreAbove.valuesPotentiallyIgnored()) {
15121507
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
1513-
layers.add(new BinaryDocValuesSyntheticFieldLoaderLayer(fieldName) {
1514-
@Override
1515-
public void writeValue(XContentBuilder b, BytesRef value) throws IOException {
1516-
b.utf8Value(value.bytes, value.offset, value.length);
1517-
}
1518-
});
1508+
layers.add(new BinaryDocValuesSyntheticFieldLoaderLayer(fieldName));
15191509
}
15201510

15211511
return new CompositeSyntheticFieldLoader(leafFieldName, fullFieldName, layers);

x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,12 +1104,7 @@ public FieldMapper.Builder getMergeBuilder() {
11041104
protected SyntheticSourceSupport syntheticSourceSupport() {
11051105
return new SyntheticSourceSupport.Native(() -> {
11061106
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>();
1107-
layers.add(new BinaryDocValuesSyntheticFieldLoaderLayer(fullPath()) {
1108-
@Override
1109-
protected void writeValue(XContentBuilder b, BytesRef value) throws IOException {
1110-
b.utf8Value(value.bytes, value.offset, value.length);
1111-
}
1112-
});
1107+
layers.add(new BinaryDocValuesSyntheticFieldLoaderLayer(fullPath()));
11131108
if (ignoreAbove.valuesPotentiallyIgnored()) {
11141109
layers.add(new CompositeSyntheticFieldLoader.StoredFieldLayer(originalName()) {
11151110
@Override

0 commit comments

Comments
 (0)