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 {
|
||||
if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
|
||||
if (allowNull) {
|
||||
|
|
|
@ -81,9 +81,10 @@ public class ExecutableSearchInput extends ExecutableInput<SearchInput, SearchIn
|
|||
if (input.getExtractKeys() != null) {
|
||||
BytesReference bytes = XContentHelper.toXContent(response, XContentType.JSON);
|
||||
// EMPTY is safe here because we never use namedObject
|
||||
XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes);
|
||||
Map<String, Object> filteredKeys = XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser);
|
||||
payload = new Payload.Simple(filteredKeys);
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, bytes)) {
|
||||
Map<String, Object> filteredKeys = XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser);
|
||||
payload = new Payload.Simple(filteredKeys);
|
||||
}
|
||||
} else {
|
||||
payload = new Payload.XContent(response);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue