Skip to content

Commit dec8b68

Browse files
committed
Change
1 parent 5fe0923 commit dec8b68

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

libs/x-content/src/main/java/org/elasticsearch/xcontent/support/MapXContentParser.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
import org.elasticsearch.xcontent.DeprecationHandler;
1313
import org.elasticsearch.xcontent.NamedXContentRegistry;
14+
import org.elasticsearch.xcontent.Text;
1415
import org.elasticsearch.xcontent.XContentLocation;
16+
import org.elasticsearch.xcontent.XContentString;
1517
import org.elasticsearch.xcontent.XContentType;
1618

1719
import java.io.IOException;
@@ -137,6 +139,20 @@ public String text() throws IOException {
137139
}
138140
}
139141

142+
@Override
143+
public XContentString optimizedText() throws IOException {
144+
if (currentToken() == Token.VALUE_STRING) {
145+
Object value = iterator.currentValue();
146+
if (value instanceof XContentString) {
147+
return (XContentString) value;
148+
} else {
149+
return new Text(value.toString());
150+
}
151+
} else {
152+
throw new IllegalStateException("Cannot get text for the current token " + currentToken());
153+
}
154+
}
155+
140156
@Override
141157
public CharBuffer charBuffer() throws IOException {
142158
throw new UnsupportedOperationException("use text() instead");
@@ -269,7 +285,7 @@ TokenIterator processValue(Object value) {
269285
return new ArrayIterator(this, childName(), (List<Object>) value).next();
270286
} else if (value instanceof Number) {
271287
currentToken = Token.VALUE_NUMBER;
272-
} else if (value instanceof String) {
288+
} else if (value instanceof String || value instanceof XContentString) {
273289
currentToken = Token.VALUE_STRING;
274290
} else if (value instanceof Boolean) {
275291
currentToken = Token.VALUE_BOOLEAN;

server/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.common.regex.Regex;
2020
import org.elasticsearch.core.Booleans;
2121
import org.elasticsearch.core.TimeValue;
22+
import org.elasticsearch.ingest.ESONIndexed;
2223

2324
import java.util.ArrayList;
2425
import java.util.Arrays;
@@ -337,7 +338,12 @@ private static Map<String, Object> filter(
337338
continue;
338339
}
339340

340-
Object value = entry.getValue();
341+
Object value;
342+
if (entry instanceof ESONIndexed.ESONObject.LazyEntry lazyEntry && lazyEntry.isUTF8Bytes()) {
343+
value = lazyEntry.utf8Bytes();
344+
} else {
345+
value = entry.getValue();
346+
}
341347

342348
CharacterRunAutomaton subIncludeAutomaton = includeAutomaton;
343349
int subIncludeState = includeState;

server/src/main/java/org/elasticsearch/ingest/ESONIndexed.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
package org.elasticsearch.ingest;
1111

12+
import org.apache.lucene.util.BytesRef;
1213
import org.elasticsearch.common.bytes.BytesReference;
1314
import org.elasticsearch.common.bytes.CompositeBytesReference;
1415
import org.elasticsearch.common.io.stream.BytesStreamOutput;
16+
import org.elasticsearch.xcontent.Text;
1517
import org.elasticsearch.xcontent.ToXContent;
1618
import org.elasticsearch.xcontent.XContentBuilder;
19+
import org.elasticsearch.xcontent.XContentString;
1720

1821
import java.io.IOException;
1922
import java.io.UncheckedIOException;
@@ -274,7 +277,7 @@ public byte type() {
274277
return ESONEntry.TYPE_OBJECT;
275278
}
276279

277-
private class LazyEntry implements Entry<String, Object> {
280+
public class LazyEntry implements Entry<String, Object> {
278281
private final String key;
279282
private final ESONSource.Value type;
280283
private final boolean nullForRawValues;
@@ -296,6 +299,19 @@ public boolean isRawValue() {
296299
return type instanceof ESONSource.FixedValue || type instanceof ESONSource.VariableValue;
297300
}
298301

302+
public boolean isUTF8Bytes() {
303+
return type.type() == ESONEntry.STRING;
304+
}
305+
306+
public XContentString utf8Bytes() {
307+
if (type instanceof ESONSource.VariableValue varValue && varValue.type() == ESONEntry.STRING) {
308+
BytesRef bytesRef = ESONSource.Values.readByteSlice(esonFlat.values().data(), varValue.position());
309+
return new Text(new XContentString.UTF8Bytes(bytesRef.bytes, bytesRef.offset, bytesRef.length), bytesRef.length);
310+
}
311+
throw new IllegalArgumentException();
312+
313+
}
314+
299315
@Override
300316
public Object getValue() {
301317
if (valueComputed == false) {

0 commit comments

Comments
 (0)