mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-16 09:54:55 +00:00
Close XContentParser when executing searches from Watcher (elastic/elasticsearch#4696)
Also removes unused method convertToObject from XContentUtils that does not close XContentParser either. Original commit: elastic/x-pack-elasticsearch@99ce977c55
This commit is contained in:
parent
84936d57ad
commit
8f70653233
@ -37,16 +37,6 @@ public class XContentUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tuple<XContentType, Object> convertToObject(BytesReference bytes) throws ElasticsearchParseException {
|
|
||||||
try {
|
|
||||||
// EMPTY is safe here because we never call namedObject
|
|
||||||
XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes);
|
|
||||||
return Tuple.tuple(parser.contentType(), readValue(parser, parser.nextToken()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new ElasticsearchParseException("Failed to parse content to map", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] readStringArray(XContentParser parser, boolean allowNull) throws IOException {
|
public static String[] readStringArray(XContentParser parser, boolean allowNull) throws IOException {
|
||||||
if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
|
if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
|
||||||
if (allowNull) {
|
if (allowNull) {
|
||||||
|
@ -81,9 +81,10 @@ public class ExecutableSearchInput extends ExecutableInput<SearchInput, SearchIn
|
|||||||
if (input.getExtractKeys() != null) {
|
if (input.getExtractKeys() != null) {
|
||||||
BytesReference bytes = XContentHelper.toXContent(response, XContentType.JSON);
|
BytesReference bytes = XContentHelper.toXContent(response, XContentType.JSON);
|
||||||
// EMPTY is safe here because we never use namedObject
|
// EMPTY is safe here because we never use namedObject
|
||||||
XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes);
|
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes)) {
|
||||||
Map<String, Object> filteredKeys = XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser);
|
Map<String, Object> filteredKeys = XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser);
|
||||||
payload = new Payload.Simple(filteredKeys);
|
payload = new Payload.Simple(filteredKeys);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
payload = new Payload.XContent(response);
|
payload = new Payload.XContent(response);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user