Consolidate more parser creation into ESTestCase
This will make it easier to add the forthcoming required argument, `NamedXContentRegistry`.
This commit is contained in:
parent
0d195f1afa
commit
49bdd29f91
|
@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -142,7 +141,7 @@ public class AliasActionsTests extends ESTestCase {
|
|||
}
|
||||
b.endObject();
|
||||
b = shuffleXContent(b, "filter");
|
||||
try (XContentParser parser = XContentHelper.createParser(b.bytes())) {
|
||||
try (XContentParser parser = createParser(b)) {
|
||||
AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
||||
assertEquals(AliasActions.Type.ADD, action.actionType());
|
||||
assertThat(action.indices(), equalTo(indices));
|
||||
|
@ -179,7 +178,7 @@ public class AliasActionsTests extends ESTestCase {
|
|||
}
|
||||
b.endObject();
|
||||
b = shuffleXContent(b);
|
||||
try (XContentParser parser = XContentHelper.createParser(b.bytes())) {
|
||||
try (XContentParser parser = createParser(b)) {
|
||||
AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
||||
assertEquals(AliasActions.Type.ADD, action.actionType());
|
||||
assertThat(action.indices(), arrayContaining(index));
|
||||
|
@ -210,7 +209,7 @@ public class AliasActionsTests extends ESTestCase {
|
|||
}
|
||||
b.endObject();
|
||||
b = shuffleXContent(b);
|
||||
try (XContentParser parser = XContentHelper.createParser(b.bytes())) {
|
||||
try (XContentParser parser = createParser(b)) {
|
||||
AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
||||
assertEquals(AliasActions.Type.REMOVE, action.actionType());
|
||||
assertThat(action.indices(), equalTo(indices));
|
||||
|
@ -233,7 +232,7 @@ public class AliasActionsTests extends ESTestCase {
|
|||
}
|
||||
b.endObject();
|
||||
b = shuffleXContent(b);
|
||||
try (XContentParser parser = XContentHelper.createParser(b.bytes())) {
|
||||
try (XContentParser parser = createParser(b)) {
|
||||
AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
||||
assertEquals(AliasActions.Type.REMOVE_INDEX, action.actionType());
|
||||
assertArrayEquals(indices, action.indices());
|
||||
|
@ -252,7 +251,7 @@ public class AliasActionsTests extends ESTestCase {
|
|||
b.endObject();
|
||||
}
|
||||
b.endObject();
|
||||
try (XContentParser parser = XContentHelper.createParser(b.bytes())) {
|
||||
try (XContentParser parser = createParser(b)) {
|
||||
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT));
|
||||
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
|
||||
assertEquals("Only one of [index] and [indices] is supported", e.getCause().getCause().getMessage());
|
||||
|
@ -270,7 +269,7 @@ public class AliasActionsTests extends ESTestCase {
|
|||
b.endObject();
|
||||
}
|
||||
b.endObject();
|
||||
try (XContentParser parser = XContentHelper.createParser(b.bytes())) {
|
||||
try (XContentParser parser = createParser(b)) {
|
||||
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT));
|
||||
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
|
||||
assertEquals("Only one of [alias] and [aliases] is supported", e.getCause().getCause().getMessage());
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
|
||||
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.mapper.AllFieldMapper;
|
||||
|
@ -290,13 +289,13 @@ public class TermVectorsUnitTests extends ESTestCase {
|
|||
|
||||
public void testMultiParser() throws Exception {
|
||||
byte[] bytes = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/termvectors/multiRequest1.json");
|
||||
XContentParser data = XContentHelper.createParser(new BytesArray(bytes));
|
||||
XContentParser data = createParser(JsonXContent.jsonXContent, bytes);
|
||||
MultiTermVectorsRequest request = new MultiTermVectorsRequest();
|
||||
request.add(new TermVectorsRequest(), data);
|
||||
checkParsedParameters(request);
|
||||
|
||||
bytes = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/termvectors/multiRequest2.json");
|
||||
data = XContentHelper.createParser(new BytesArray(bytes));
|
||||
data = createParser(JsonXContent.jsonXContent, new BytesArray(bytes));
|
||||
request = new MultiTermVectorsRequest();
|
||||
request.add(new TermVectorsRequest(), data);
|
||||
checkParsedParameters(request);
|
||||
|
@ -326,7 +325,7 @@ public class TermVectorsUnitTests extends ESTestCase {
|
|||
// issue #12311
|
||||
public void testMultiParserFilter() throws Exception {
|
||||
byte[] bytes = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/termvectors/multiRequest3.json");
|
||||
XContentParser data = XContentHelper.createParser(new BytesArray(bytes));
|
||||
XContentParser data = createParser(JsonXContent.jsonXContent, bytes);
|
||||
MultiTermVectorsRequest request = new MultiTermVectorsRequest();
|
||||
request.add(new TermVectorsRequest(), data);
|
||||
checkParsedFilterParameters(request);
|
||||
|
|
|
@ -82,7 +82,7 @@ public abstract class AbstractShapeBuilderTestCase<SB extends ShapeBuilder> exte
|
|||
}
|
||||
XContentBuilder builder = testShape.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
XContentBuilder shuffled = shuffleXContent(builder);
|
||||
XContentParser shapeParser = XContentHelper.createParser(shuffled.bytes());
|
||||
XContentParser shapeParser = createParser(shuffled);
|
||||
shapeParser.nextToken();
|
||||
ShapeBuilder parsedShape = ShapeBuilder.parse(shapeParser);
|
||||
assertNotSame(testShape, parsedShape);
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.common.xcontent.cbor;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -34,7 +33,7 @@ public class CborXContentParserTests extends ESTestCase {
|
|||
for (int i = 0; i < 2; i++) {
|
||||
// Running this part twice triggers the issue.
|
||||
// See https://github.com/elastic/elasticsearch/issues/8629
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.CBOR).createParser(ref);
|
||||
XContentParser parser = createParser(CborXContent.cborXContent, ref);
|
||||
while (parser.nextToken() != null) {
|
||||
parser.utf8Bytes();
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
|||
|
||||
try {
|
||||
XContent xContent = XContentFactory.xContent(builder.contentType());
|
||||
XContentParser jsonParser = xContent.createParser(expected.bytes());
|
||||
XContentParser testParser = xContent.createParser(builder.bytes());
|
||||
XContentParser jsonParser = createParser(xContent, expected.bytes());
|
||||
XContentParser testParser = createParser(xContent, builder.bytes());
|
||||
|
||||
while (true) {
|
||||
XContentParser.Token token1 = jsonParser.nextToken();
|
||||
|
|
|
@ -28,8 +28,8 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.BooleanFieldMapper.BooleanFieldType;
|
||||
import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType;
|
||||
|
@ -198,12 +198,14 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
|
|||
private Mapper parse(DocumentMapper mapper, DocumentMapperParser parser, XContentBuilder builder) throws Exception {
|
||||
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
SourceToParse source = SourceToParse.source("test", mapper.type(), "some_id", builder.bytes());
|
||||
ParseContext.InternalParseContext ctx = new ParseContext.InternalParseContext(settings, parser, mapper, source, XContentHelper.createParser(source.source()));
|
||||
assertEquals(XContentParser.Token.START_OBJECT, ctx.parser().nextToken());
|
||||
ctx.parser().nextToken();
|
||||
DocumentParser.parseObjectOrNested(ctx, mapper.root(), true);
|
||||
Mapping mapping = DocumentParser.createDynamicUpdate(mapper.mapping(), mapper, ctx.getDynamicMappers());
|
||||
return mapping == null ? null : mapping.root();
|
||||
try (XContentParser xContentParser = createParser(JsonXContent.jsonXContent, source.source())) {
|
||||
ParseContext.InternalParseContext ctx = new ParseContext.InternalParseContext(settings, parser, mapper, source, xContentParser);
|
||||
assertEquals(XContentParser.Token.START_OBJECT, ctx.parser().nextToken());
|
||||
ctx.parser().nextToken();
|
||||
DocumentParser.parseObjectOrNested(ctx, mapper.root(), true);
|
||||
Mapping mapping = DocumentParser.createDynamicUpdate(mapper.mapping(), mapper, ctx.getDynamicMappers());
|
||||
return mapping == null ? null : mapping.root();
|
||||
}
|
||||
}
|
||||
|
||||
public void testDynamicMappingsNotNeeded() throws Exception {
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
||||
|
@ -98,7 +97,7 @@ public class InnerHitBuilderTests extends ESTestCase {
|
|||
shuffled.prettyPrint();
|
||||
}
|
||||
|
||||
XContentParser parser = XContentHelper.createParser(shuffled.bytes());
|
||||
XContentParser parser = createParser(shuffled);
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
|
||||
InnerHitBuilder secondInnerHits = InnerHitBuilder.fromXContent(context);
|
||||
assertThat(innerHit, not(sameInstance(secondInnerHits)));
|
||||
|
|
|
@ -23,11 +23,10 @@ import org.apache.lucene.spatial.prefix.tree.Cell;
|
|||
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
|
||||
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.GeoUtils;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -384,25 +383,25 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
for (int i = 0; i < 100; i++) {
|
||||
double lat = randomDouble() * 180 - 90 + randomIntBetween(-1000, 1000) * 180;
|
||||
double lon = randomDouble() * 360 - 180 + randomIntBetween(-1000, 1000) * 360;
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("lat", lat).field("lon", lon).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("lat", lat).field("lon", lon).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
GeoPoint point = GeoUtils.parseGeoPoint(parser);
|
||||
assertThat(point, equalTo(new GeoPoint(lat, lon)));
|
||||
jsonBytes = jsonBuilder().startObject().field("lat", String.valueOf(lat)).field("lon", String.valueOf(lon)).endObject().bytes();
|
||||
parser = XContentHelper.createParser(jsonBytes);
|
||||
json = jsonBuilder().startObject().field("lat", String.valueOf(lat)).field("lon", String.valueOf(lon)).endObject();
|
||||
parser = createParser(json);
|
||||
parser.nextToken();
|
||||
point = GeoUtils.parseGeoPoint(parser);
|
||||
assertThat(point, equalTo(new GeoPoint(lat, lon)));
|
||||
jsonBytes = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).endArray().endObject().bytes();
|
||||
parser = XContentHelper.createParser(jsonBytes);
|
||||
json = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).endArray().endObject();
|
||||
parser = createParser(json);
|
||||
while (parser.currentToken() != Token.START_ARRAY) {
|
||||
parser.nextToken();
|
||||
}
|
||||
point = GeoUtils.parseGeoPoint(parser);
|
||||
assertThat(point, equalTo(new GeoPoint(lat, lon)));
|
||||
jsonBytes = jsonBuilder().startObject().field("foo", lat + "," + lon).endObject().bytes();
|
||||
parser = XContentHelper.createParser(jsonBytes);
|
||||
json = jsonBuilder().startObject().field("foo", lat + "," + lon).endObject();
|
||||
parser = createParser(json);
|
||||
while (parser.currentToken() != Token.VALUE_STRING) {
|
||||
parser.nextToken();
|
||||
}
|
||||
|
@ -418,14 +417,14 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
for (int j = 0; j < geoHashLength; j++) {
|
||||
geohashBuilder.append(BASE_32[randomInt(BASE_32.length - 1)]);
|
||||
}
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("geohash", geohashBuilder.toString()).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("geohash", geohashBuilder.toString()).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
GeoPoint point = GeoUtils.parseGeoPoint(parser);
|
||||
assertThat(point.lat(), allOf(lessThanOrEqualTo(90.0), greaterThanOrEqualTo(-90.0)));
|
||||
assertThat(point.lon(), allOf(lessThanOrEqualTo(180.0), greaterThanOrEqualTo(-180.0)));
|
||||
jsonBytes = jsonBuilder().startObject().field("geohash", geohashBuilder.toString()).endObject().bytes();
|
||||
parser = XContentHelper.createParser(jsonBytes);
|
||||
json = jsonBuilder().startObject().field("geohash", geohashBuilder.toString()).endObject();
|
||||
parser = createParser(json);
|
||||
while (parser.currentToken() != Token.VALUE_STRING) {
|
||||
parser.nextToken();
|
||||
}
|
||||
|
@ -436,8 +435,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseGeoPointGeohashWrongType() throws IOException {
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("geohash", 1.0).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("geohash", 1.0).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), containsString("geohash must be a string"));
|
||||
|
@ -445,8 +444,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
|
||||
public void testParseGeoPointLatNoLon() throws IOException {
|
||||
double lat = 0.0;
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("lat", lat).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("lat", lat).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), is("field [lon] missing"));
|
||||
|
@ -454,8 +453,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
|
||||
public void testParseGeoPointLonNoLat() throws IOException {
|
||||
double lon = 0.0;
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("lon", lon).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("lon", lon).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), is("field [lat] missing"));
|
||||
|
@ -463,8 +462,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
|
||||
public void testParseGeoPointLonWrongType() throws IOException {
|
||||
double lat = 0.0;
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("lat", lat).field("lon", false).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("lat", lat).field("lon", false).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), is("longitude must be a number"));
|
||||
|
@ -472,8 +471,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
|
||||
public void testParseGeoPointLatWrongType() throws IOException {
|
||||
double lon = 0.0;
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("lat", false).field("lon", lon).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("lat", false).field("lon", lon).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), is("latitude must be a number"));
|
||||
|
@ -482,8 +481,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
public void testParseGeoPointExtraField() throws IOException {
|
||||
double lat = 0.0;
|
||||
double lon = 0.0;
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("lat", lat).field("lon", lon).field("foo", true).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("lat", lat).field("lon", lon).field("foo", true).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), is("field must be either [lat], [lon] or [geohash]"));
|
||||
|
@ -493,9 +492,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
double lat = 0.0;
|
||||
double lon = 0.0;
|
||||
String geohash = "abcd";
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("lat", lat).field("lon", lon).field("geohash", geohash).endObject()
|
||||
.bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("lat", lat).field("lon", lon).field("geohash", geohash).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
parser.nextToken();
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), containsString("field must be either lat/lon or geohash"));
|
||||
|
@ -505,9 +503,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
double lat = 0.0;
|
||||
double lon = 0.0;
|
||||
double elev = 0.0;
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).value(elev).endArray().endObject()
|
||||
.bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).value(elev).endArray().endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
while (parser.currentToken() != Token.START_ARRAY) {
|
||||
parser.nextToken();
|
||||
}
|
||||
|
@ -518,8 +515,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
public void testParseGeoPointArrayWrongType() throws IOException {
|
||||
double lat = 0.0;
|
||||
boolean lon = false;
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).endArray().endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).endArray().endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
while (parser.currentToken() != Token.START_ARRAY) {
|
||||
parser.nextToken();
|
||||
}
|
||||
|
@ -528,8 +525,8 @@ public class GeoUtilsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseGeoPointInvalidType() throws IOException {
|
||||
BytesReference jsonBytes = jsonBuilder().startObject().field("foo", 5).endObject().bytes();
|
||||
XContentParser parser = XContentHelper.createParser(jsonBytes);
|
||||
XContentBuilder json = jsonBuilder().startObject().field("foo", 5).endObject();
|
||||
XContentParser parser = createParser(json);
|
||||
while (parser.currentToken() != Token.VALUE_NUMBER) {
|
||||
parser.nextToken();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRespon
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
|
@ -163,7 +164,7 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
|
|||
|
||||
|
||||
XContentBuilder prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();
|
||||
prettyJsonBuilder.copyCurrentStructure(XContentFactory.xContent(responseStrings).createParser(responseStrings));
|
||||
prettyJsonBuilder.copyCurrentStructure(createParser(JsonXContent.jsonXContent, responseStrings));
|
||||
assertThat(responseStrings, equalTo(prettyJsonBuilder.string()));
|
||||
|
||||
params.put("pretty", "false");
|
||||
|
@ -176,7 +177,7 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
|
|||
responseStrings = responseBuilder.string();
|
||||
|
||||
prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();
|
||||
prettyJsonBuilder.copyCurrentStructure(XContentFactory.xContent(responseStrings).createParser(responseStrings));
|
||||
prettyJsonBuilder.copyCurrentStructure(createParser(JsonXContent.jsonXContent, responseStrings));
|
||||
assertThat(responseStrings, not(equalTo(prettyJsonBuilder.string())));
|
||||
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class IngestMetadataTests extends ESTestCase {
|
|||
ingestMetadata.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
XContentBuilder shuffled = shuffleXContent(builder);
|
||||
final XContentParser parser = XContentFactory.xContent(shuffled.bytes()).createParser(shuffled.bytes());
|
||||
final XContentParser parser = createParser(shuffled);
|
||||
MetaData.Custom custom = ingestMetadata.fromXContent(parser);
|
||||
assertTrue(custom instanceof IngestMetadata);
|
||||
IngestMetadata m = (IngestMetadata) custom;
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
|||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
|
@ -38,12 +37,12 @@ import static org.mockito.Mockito.mock;
|
|||
public class RestAnalyzeActionTests extends ESTestCase {
|
||||
|
||||
public void testParseXContentForAnalyzeRequest() throws Exception {
|
||||
XContentParser content = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser content = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("tokenizer", "keyword")
|
||||
.array("filter", "lowercase")
|
||||
.endObject().bytes());
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("tokenizer", "keyword")
|
||||
.array("filter", "lowercase")
|
||||
.endObject());
|
||||
|
||||
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
|
||||
|
||||
|
@ -59,24 +58,24 @@ public class RestAnalyzeActionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseXContentForAnalyzeRequestWithCustomFilters() throws Exception {
|
||||
XContentParser content = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser content = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("tokenizer", "keyword")
|
||||
.startArray("filter")
|
||||
.value("lowercase")
|
||||
.startObject()
|
||||
.field("type", "stop")
|
||||
.array("stopwords", "foo", "buzz")
|
||||
.endObject()
|
||||
.endArray()
|
||||
.startArray("char_filter")
|
||||
.startObject()
|
||||
.field("type", "mapping")
|
||||
.array("mappings", "ph => f", "qu => q")
|
||||
.endObject()
|
||||
.endArray()
|
||||
.endObject().bytes());
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("tokenizer", "keyword")
|
||||
.startArray("filter")
|
||||
.value("lowercase")
|
||||
.startObject()
|
||||
.field("type", "stop")
|
||||
.array("stopwords", "foo", "buzz")
|
||||
.endObject()
|
||||
.endArray()
|
||||
.startArray("char_filter")
|
||||
.startObject()
|
||||
.field("type", "mapping")
|
||||
.array("mappings", "ph => f", "qu => q")
|
||||
.endObject()
|
||||
.endArray()
|
||||
.endObject());
|
||||
|
||||
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
|
||||
|
||||
|
@ -101,11 +100,11 @@ public class RestAnalyzeActionTests extends ESTestCase {
|
|||
|
||||
public void testParseXContentForAnalyzeRequestWithUnknownParamThrowsException() throws Exception {
|
||||
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
|
||||
XContentParser invalidContent = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser invalidContent = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("unknown", "keyword")
|
||||
.endObject().bytes());
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("unknown", "keyword")
|
||||
.endObject());
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||
() -> RestAnalyzeAction.buildFromContent(invalidContent, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY)));
|
||||
assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
|
||||
|
@ -113,10 +112,10 @@ public class RestAnalyzeActionTests extends ESTestCase {
|
|||
|
||||
public void testParseXContentForAnalyzeRequestWithInvalidStringExplainParamThrowsException() throws Exception {
|
||||
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
|
||||
XContentParser invalidExplain = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser invalidExplain = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("explain", "fals")
|
||||
.endObject().bytes());
|
||||
.field("explain", "fals")
|
||||
.endObject());
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||
() -> RestAnalyzeAction.buildFromContent(invalidExplain, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY)));
|
||||
assertThat(e.getMessage(), startsWith("explain must be either 'true' or 'false'"));
|
||||
|
@ -124,48 +123,48 @@ public class RestAnalyzeActionTests extends ESTestCase {
|
|||
|
||||
public void testDeprecatedParamIn2xException() throws Exception {
|
||||
{
|
||||
XContentParser parser = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser parser = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("tokenizer", "keyword")
|
||||
.array("filters", "lowercase")
|
||||
.endObject().bytes());
|
||||
.endObject());
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(parser,
|
||||
new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY)));
|
||||
assertThat(e.getMessage(), startsWith("Unknown parameter [filters]"));
|
||||
}
|
||||
|
||||
{
|
||||
XContentParser parser = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser parser = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("tokenizer", "keyword")
|
||||
.array("token_filters", "lowercase")
|
||||
.endObject().bytes());
|
||||
.endObject());
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(parser,
|
||||
new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY)));
|
||||
assertThat(e.getMessage(), startsWith("Unknown parameter [token_filters]"));
|
||||
}
|
||||
|
||||
{
|
||||
XContentParser parser = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser parser = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("tokenizer", "keyword")
|
||||
.array("char_filters", "lowercase")
|
||||
.endObject().bytes());
|
||||
.endObject());
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(parser,
|
||||
new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY)));
|
||||
assertThat(e.getMessage(), startsWith("Unknown parameter [char_filters]"));
|
||||
}
|
||||
|
||||
{
|
||||
XContentParser parser = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser parser = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("text", "THIS IS A TEST")
|
||||
.field("tokenizer", "keyword")
|
||||
.array("token_filter", "lowercase")
|
||||
.endObject().bytes());
|
||||
.endObject());
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(parser,
|
||||
new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY)));
|
||||
assertThat(e.getMessage(), startsWith("Unknown parameter [token_filter]"));
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -79,7 +78,7 @@ public class ScriptMetaDataTests extends ESTestCase {
|
|||
xContentBuilder.endObject();
|
||||
xContentBuilder = shuffleXContent(xContentBuilder);
|
||||
|
||||
XContentParser parser = XContentHelper.createParser(xContentBuilder.bytes());
|
||||
XContentParser parser = createParser(xContentBuilder);
|
||||
parser.nextToken();
|
||||
ScriptMetaData result = ScriptMetaData.PROTO.fromXContent(parser);
|
||||
assertEquals(expected, result);
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -45,7 +44,7 @@ public class ScriptTests extends ESTestCase {
|
|||
Script expectedScript = createScript(xContent);
|
||||
try (XContentBuilder builder = XContentBuilder.builder(xContent)) {
|
||||
expectedScript.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
try (XContentParser parser = XContentHelper.createParser(builder.bytes())) {
|
||||
try (XContentParser parser = createParser(builder)) {
|
||||
Script actualScript = Script.parse(parser, ParseFieldMatcher.STRICT);
|
||||
assertThat(actualScript, equalTo(expectedScript));
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.query.QueryParser;
|
||||
import org.elasticsearch.index.query.TermQueryBuilder;
|
||||
|
@ -207,7 +207,7 @@ public class SearchModuleTests extends ModuleTestCase {
|
|||
assertThat(module.getQueryParserRegistry().getNames(), containsInAnyOrder(supportedQueries));
|
||||
|
||||
IndicesQueriesRegistry indicesQueriesRegistry = module.getQueryParserRegistry();
|
||||
XContentParser dummyParser = XContentHelper.createParser(new BytesArray("{}"));
|
||||
XContentParser dummyParser = createParser(JsonXContent.jsonXContent, new BytesArray("{}"));
|
||||
for (String queryName : supportedQueries) {
|
||||
indicesQueriesRegistry.lookup(queryName, ParseFieldMatcher.EMPTY, dummyParser.getTokenLocation());
|
||||
}
|
||||
|
|
|
@ -19,58 +19,30 @@
|
|||
|
||||
package org.elasticsearch.search.aggregations;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsModule;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.search.SearchExtRegistry;
|
||||
import org.elasticsearch.search.SearchRequestParsers;
|
||||
import org.elasticsearch.test.AbstractQueryTestCase;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.indices.IndicesModule;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.script.ScriptModule;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
import org.elasticsearch.test.AbstractQueryTestCase;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.IndexSettingsModule;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.elasticsearch.test.ClusterServiceUtils.createClusterService;
|
||||
import static org.elasticsearch.test.ClusterServiceUtils.setState;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
public class AggregatorParsingTests extends ESTestCase {
|
||||
|
@ -114,23 +86,23 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testTwoTypes() throws Exception {
|
||||
String source = JsonXContent.contentBuilder()
|
||||
XContentBuilder source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject("in_stock")
|
||||
.startObject("filter")
|
||||
.startObject("range")
|
||||
.startObject("stock")
|
||||
.field("gt", 0)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("terms")
|
||||
.field("field", "stock")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
.startObject("in_stock")
|
||||
.startObject("filter")
|
||||
.startObject("range")
|
||||
.startObject("stock")
|
||||
.field("gt", 0)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("terms")
|
||||
.field("field", "stock")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
XContentParser parser = createParser(source);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
aggParsers.parseAggregators(parseContext);
|
||||
|
@ -141,7 +113,7 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testTwoAggs() throws Exception {
|
||||
String source = JsonXContent.contentBuilder()
|
||||
XContentBuilder source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
|
@ -163,9 +135,9 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
XContentParser parser = createParser(source);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
aggParsers.parseAggregators(parseContext);
|
||||
|
@ -191,7 +163,7 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
String source = JsonXContent.contentBuilder()
|
||||
XContentBuilder source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject(name)
|
||||
.startObject("filter")
|
||||
|
@ -202,9 +174,9 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
XContentParser parser = createParser(source);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
aggParsers.parseAggregators(parseContext);
|
||||
|
@ -216,21 +188,21 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
|
||||
public void testSameAggregationName() throws Exception {
|
||||
final String name = randomAsciiOfLengthBetween(1, 10);
|
||||
String source = JsonXContent.contentBuilder()
|
||||
XContentBuilder source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject(name)
|
||||
.startObject("terms")
|
||||
.field("field", "a")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject(name)
|
||||
.startObject("terms")
|
||||
.field("field", "b")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
.startObject(name)
|
||||
.startObject("terms")
|
||||
.field("field", "a")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject(name)
|
||||
.startObject("terms")
|
||||
.field("field", "b")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
XContentParser parser = createParser(source);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
aggParsers.parseAggregators(parseContext);
|
||||
|
@ -241,7 +213,7 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissingName() throws Exception {
|
||||
String source = JsonXContent.contentBuilder()
|
||||
XContentBuilder source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
|
@ -257,9 +229,9 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
//.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
XContentParser parser = createParser(source);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
aggParsers.parseAggregators(parseContext);
|
||||
|
@ -270,7 +242,7 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissingType() throws Exception {
|
||||
String source = JsonXContent.contentBuilder()
|
||||
XContentBuilder source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
|
@ -286,9 +258,9 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
XContentParser parser = createParser(source);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
aggParsers.parseAggregators(parseContext);
|
||||
|
|
|
@ -110,7 +110,7 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
|
|||
}
|
||||
factoriesBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentBuilder shuffled = shuffleXContent(builder);
|
||||
XContentParser parser = XContentFactory.xContent(shuffled.bytes()).createParser(shuffled.bytes());
|
||||
XContentParser parser = createParser(shuffled);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
||||
|
|
|
@ -112,7 +112,7 @@ public abstract class BasePipelineAggregationTestCase<AF extends AbstractPipelin
|
|||
}
|
||||
factoriesBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentBuilder shuffled = shuffleXContent(builder);
|
||||
XContentParser parser = XContentFactory.xContent(shuffled.bytes()).createParser(shuffled.bytes());
|
||||
XContentParser parser = createParser(shuffled);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
String contentString = factoriesBuilder.toString();
|
||||
logger.info("Content string: {}", contentString);
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.search.aggregations.metrics;
|
|||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.MatchNoneQueryBuilder;
|
||||
|
@ -31,13 +30,11 @@ import org.elasticsearch.index.query.QueryBuilders;
|
|||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
|
||||
import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter;
|
||||
import org.elasticsearch.search.slice.SliceBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder;
|
||||
|
||||
public class FiltersTests extends BaseAggregationTestCase<FiltersAggregationBuilder> {
|
||||
|
||||
@Override
|
||||
|
@ -90,7 +87,7 @@ public class FiltersTests extends BaseAggregationTestCase<FiltersAggregationBuil
|
|||
builder.startObject();
|
||||
builder.startArray("filters").endArray();
|
||||
builder.endObject();
|
||||
XContentParser parser = XContentHelper.createParser(shuffleXContent(builder).bytes());
|
||||
XContentParser parser = createParser(shuffleXContent(builder));
|
||||
parser.nextToken();
|
||||
QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry(), parser,
|
||||
ParseFieldMatcher.STRICT);
|
||||
|
@ -103,7 +100,7 @@ public class FiltersTests extends BaseAggregationTestCase<FiltersAggregationBuil
|
|||
builder.startArray("filters").endArray();
|
||||
builder.field("other_bucket_key", "some_key");
|
||||
builder.endObject();
|
||||
parser = XContentHelper.createParser(shuffleXContent(builder).bytes());
|
||||
parser = createParser(shuffleXContent(builder));
|
||||
parser.nextToken();
|
||||
context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
|
||||
filters = FiltersAggregationBuilder.parse("agg_name", context);
|
||||
|
@ -116,7 +113,7 @@ public class FiltersTests extends BaseAggregationTestCase<FiltersAggregationBuil
|
|||
builder.field("other_bucket", false);
|
||||
builder.field("other_bucket_key", "some_key");
|
||||
builder.endObject();
|
||||
parser = XContentHelper.createParser(shuffleXContent(builder).bytes());
|
||||
parser = createParser(shuffleXContent(builder));
|
||||
parser.nextToken();
|
||||
context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
|
||||
filters = FiltersAggregationBuilder.parse("agg_name", context);
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.metrics;
|
|||
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.AbstractQueryTestCase;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.script.Script;
|
||||
|
@ -186,7 +187,7 @@ public class TopHitsTests extends BaseAggregationTestCase<TopHitsAggregationBuil
|
|||
" }\n" +
|
||||
"}";
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, source);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
aggParsers.parseAggregators(parseContext);
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
|
|||
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregationBuilder;
|
||||
|
||||
|
@ -45,7 +46,7 @@ public class ExtendedStatsBucketTests extends AbstractBucketMetricsTestCase<Exte
|
|||
.endObject()
|
||||
.string();
|
||||
|
||||
XContentParser parser = XContentFactory.xContent(content).createParser(content);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
parser.nextToken(); // skip object start
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
|
|||
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregationBuilder;
|
||||
|
||||
|
@ -50,7 +51,7 @@ public class PercentilesBucketTests extends AbstractBucketMetricsTestCase<Percen
|
|||
.endObject()
|
||||
.string();
|
||||
|
||||
XContentParser parser = XContentFactory.xContent(content).createParser(content);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
parser.nextToken(); // skip object start
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
package org.elasticsearch.search.aggregations.pipeline.moving.avg;
|
||||
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase;
|
||||
import org.elasticsearch.search.aggregations.PipelineAggregationBuilder;
|
||||
|
@ -106,7 +106,7 @@ public class MovAvgTests extends BasePipelineAggregationTestCase<MovAvgPipelineA
|
|||
" }" +
|
||||
" }" +
|
||||
"}";
|
||||
XContentParser parser = XContentFactory.xContent(json).createParser(json);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, json);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
||||
|
|
|
@ -229,7 +229,7 @@ public class IncludeExcludeTests extends ESTestCase {
|
|||
incExc.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
|
||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(builder);
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
assertEquals(token, XContentParser.Token.START_OBJECT);
|
||||
token = parser.nextToken();
|
||||
|
@ -276,7 +276,7 @@ public class IncludeExcludeTests extends ESTestCase {
|
|||
incExc.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
|
||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(builder);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
assertEquals(token, XContentParser.Token.START_OBJECT);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.query.RandomQueryBuilder;
|
||||
|
@ -60,16 +61,15 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
builder.prettyPrint();
|
||||
}
|
||||
testSearchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
assertParseSearchSource(testSearchSourceBuilder, builder.bytes());
|
||||
assertParseSearchSource(testSearchSourceBuilder, createParser(builder));
|
||||
}
|
||||
|
||||
private void assertParseSearchSource(SearchSourceBuilder testBuilder, BytesReference searchSourceAsBytes) throws IOException {
|
||||
assertParseSearchSource(testBuilder, searchSourceAsBytes, ParseFieldMatcher.STRICT);
|
||||
private void assertParseSearchSource(SearchSourceBuilder testBuilder, XContentParser parser) throws IOException {
|
||||
assertParseSearchSource(testBuilder, parser, ParseFieldMatcher.STRICT);
|
||||
}
|
||||
|
||||
private void assertParseSearchSource(SearchSourceBuilder testBuilder, BytesReference searchSourceAsBytes, ParseFieldMatcher pfm)
|
||||
private void assertParseSearchSource(SearchSourceBuilder testBuilder, XContentParser parser, ParseFieldMatcher pfm)
|
||||
throws IOException {
|
||||
XContentParser parser = XContentFactory.xContent(searchSourceAsBytes).createParser(searchSourceAsBytes);
|
||||
QueryParseContext parseContext = new QueryParseContext(searchRequestParsers.queryParsers, parser, pfm);
|
||||
if (randomBoolean()) {
|
||||
parser.nextToken(); // sometimes we move it on the START_OBJECT to
|
||||
|
@ -112,7 +112,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
public void testParseIncludeExclude() throws IOException {
|
||||
{
|
||||
String restContent = " { \"_source\": { \"includes\": \"include\", \"excludes\": \"*.field2\"}}";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertArrayEquals(new String[]{"*.field2"}, searchSourceBuilder.fetchSource().excludes());
|
||||
|
@ -121,7 +121,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
}
|
||||
{
|
||||
String restContent = " { \"_source\": false}";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertArrayEquals(new String[]{}, searchSourceBuilder.fetchSource().excludes());
|
||||
|
@ -144,7 +144,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
" } }";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
ParsingException e = expectThrows(ParsingException.class, () -> SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers));
|
||||
assertEquals("[multi_match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]", e.getMessage());
|
||||
|
@ -154,7 +154,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
public void testParseSort() throws IOException {
|
||||
{
|
||||
String restContent = " { \"sort\": \"foo\"}";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertEquals(1, searchSourceBuilder.sorts().size());
|
||||
|
@ -170,7 +170,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
" { \"age\" : \"desc\" },\n" +
|
||||
" \"_score\"\n" +
|
||||
" ]}";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertEquals(5, searchSourceBuilder.sorts().size());
|
||||
|
@ -194,7 +194,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
"}\n";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertEquals(1, searchSourceBuilder.aggregations().count());
|
||||
|
@ -210,7 +210,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
"}\n";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertEquals(1, searchSourceBuilder.aggregations().count());
|
||||
|
@ -236,7 +236,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
"}\n";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertEquals(1, searchSourceBuilder.rescores().size());
|
||||
|
@ -259,7 +259,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
" }\n" +
|
||||
" } ]\n" +
|
||||
"}\n";
|
||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertEquals(1, searchSourceBuilder.rescores().size());
|
||||
|
@ -272,7 +272,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
public void testTimeoutWithUnits() throws IOException {
|
||||
final String timeout = randomTimeValue();
|
||||
final String query = "{ \"query\": { \"match_all\": {}}, \"timeout\": \"" + timeout + "\"}";
|
||||
try (XContentParser parser = XContentFactory.xContent(query).createParser(query)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, query)) {
|
||||
final SearchSourceBuilder builder = SearchSourceBuilder.fromXContent(createParseContext(parser),
|
||||
searchRequestParsers.aggParsers, searchRequestParsers.suggesters, searchRequestParsers.searchExtParsers);
|
||||
assertThat(builder.timeout(), equalTo(TimeValue.parseTimeValue(timeout, null, "timeout")));
|
||||
|
@ -282,7 +282,7 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
|||
public void testTimeoutWithoutUnits() throws IOException {
|
||||
final int timeout = randomIntBetween(1, 1024);
|
||||
final String query = "{ \"query\": { \"match_all\": {}}, \"timeout\": \"" + timeout + "\"}";
|
||||
try (XContentParser parser = XContentFactory.xContent(query).createParser(query)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, query)) {
|
||||
final ElasticsearchParseException e =
|
||||
expectThrows(
|
||||
ElasticsearchParseException.class,
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
|
@ -129,7 +128,7 @@ public class HighlightBuilderTests extends ESTestCase {
|
|||
highlightBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentBuilder shuffled = shuffleXContent(builder);
|
||||
|
||||
XContentParser parser = XContentHelper.createParser(shuffled.bytes());
|
||||
XContentParser parser = createParser(shuffled);
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
|
||||
parser.nextToken();
|
||||
HighlightBuilder secondHighlightBuilder;
|
||||
|
|
|
@ -61,7 +61,7 @@ public class HighlightFieldTests extends ESTestCase {
|
|||
builder.startObject(); // we need to wrap xContent output in proper object to create a parser for it
|
||||
builder = highlightField.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
XContentParser parser = xcontentType.xContent().createParser(builder.bytes());
|
||||
XContentParser parser = createParser(builder);
|
||||
parser.nextToken(); // skip to the opening object token, fromXContent advances from here and starts with the field name
|
||||
HighlightField parsedField = HighlightField.fromXContent(parser);
|
||||
assertEquals(highlightField, parsedField);
|
||||
|
|
|
@ -57,7 +57,7 @@ public class InternalNestedIdentityTests extends ESTestCase {
|
|||
builder.prettyPrint();
|
||||
}
|
||||
builder = nestedIdentity.innerToXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentParser parser = xcontentType.xContent().createParser(builder.bytes());
|
||||
XContentParser parser = createParser(builder);
|
||||
InternalNestedIdentity parsedNestedIdentity = InternalNestedIdentity.fromXContent(parser);
|
||||
assertEquals(nestedIdentity, parsedNestedIdentity);
|
||||
assertNull(parser.nextToken());
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
|
@ -119,7 +118,7 @@ public class QueryRescoreBuilderTests extends ESTestCase {
|
|||
XContentBuilder shuffled = shuffleXContent(builder);
|
||||
|
||||
|
||||
XContentParser parser = XContentHelper.createParser(shuffled.bytes());
|
||||
XContentParser parser = createParser(shuffled);
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
parser.nextToken();
|
||||
RescoreBuilder<?> secondRescoreBuilder = RescoreBuilder.parseFromXContent(context);
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.action.search.ClearScrollRequest;
|
|||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
|
@ -38,10 +37,10 @@ import static org.mockito.Mockito.mock;
|
|||
|
||||
public class RestClearScrollActionTests extends ESTestCase {
|
||||
public void testParseClearScrollRequest() throws Exception {
|
||||
XContentParser content = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser content = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.array("scroll_id", "value_1", "value_2")
|
||||
.endObject().bytes());
|
||||
.endObject());
|
||||
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
|
||||
RestClearScrollAction.buildFromContent(content, clearScrollRequest);
|
||||
assertThat(clearScrollRequest.scrollIds(), contains("value_1", "value_2"));
|
||||
|
@ -55,11 +54,11 @@ public class RestClearScrollActionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseClearScrollRequestWithUnknownParamThrowsException() throws Exception {
|
||||
XContentParser invalidContent = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser invalidContent = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.array("scroll_id", "value_1", "value_2")
|
||||
.field("unknown", "keyword")
|
||||
.endObject().bytes());
|
||||
.endObject());
|
||||
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
|
||||
|
||||
Exception e = expectThrows(IllegalArgumentException.class,
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
|
@ -38,11 +37,11 @@ import static org.mockito.Mockito.mock;
|
|||
|
||||
public class RestSearchScrollActionTests extends ESTestCase {
|
||||
public void testParseSearchScrollRequest() throws Exception {
|
||||
XContentParser content = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser content = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("scroll_id", "SCROLL_ID")
|
||||
.field("scroll", "1m")
|
||||
.endObject().bytes());
|
||||
.endObject());
|
||||
|
||||
SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
|
||||
RestSearchScrollAction.buildFromContent(content, searchScrollRequest);
|
||||
|
@ -60,11 +59,11 @@ public class RestSearchScrollActionTests extends ESTestCase {
|
|||
|
||||
public void testParseSearchScrollRequestWithUnknownParamThrowsException() throws Exception {
|
||||
SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
|
||||
XContentParser invalidContent = XContentHelper.createParser(XContentFactory.jsonBuilder()
|
||||
XContentParser invalidContent = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("scroll_id", "value_2")
|
||||
.field("unknown", "keyword")
|
||||
.endObject().bytes());
|
||||
.endObject());
|
||||
|
||||
Exception e = expectThrows(IllegalArgumentException.class,
|
||||
() -> RestSearchScrollAction.buildFromContent(invalidContent, searchScrollRequest));
|
||||
|
|
|
@ -25,13 +25,12 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
@ -525,11 +524,7 @@ public class SearchScrollIT extends ESIntegTestCase {
|
|||
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
|
||||
BytesReference bytesReference = builder.bytes();
|
||||
Map<String, Object> map;
|
||||
try (XContentParser parser = XContentFactory.xContent(bytesReference).createParser(bytesReference)) {
|
||||
map = parser.map();
|
||||
}
|
||||
Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||
|
||||
assertThat(map.get("succeeded"), is(succeed));
|
||||
assertThat(map.get("num_freed"), equalTo(numFreed));
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|||
import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
|
@ -189,7 +188,7 @@ public class SearchAfterBuilderTests extends ESTestCase {
|
|||
builder.startObject();
|
||||
searchAfterBuilder.innerToXContent(builder);
|
||||
builder.endObject();
|
||||
XContentParser parser = XContentHelper.createParser(shuffleXContent(builder).bytes());
|
||||
XContentParser parser = createParser(shuffleXContent(builder));
|
||||
new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
|||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
|
@ -125,7 +124,7 @@ public class SliceBuilderTests extends ESTestCase {
|
|||
builder.startObject();
|
||||
sliceBuilder.innerToXContent(builder);
|
||||
builder.endObject();
|
||||
XContentParser parser = XContentHelper.createParser(shuffleXContent(builder).bytes());
|
||||
XContentParser parser = createParser(shuffleXContent(builder));
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser,
|
||||
ParseFieldMatcher.STRICT);
|
||||
SliceBuilder secondSliceBuilder = SliceBuilder.fromXContent(context);
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
@ -138,7 +137,7 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
|
|||
}
|
||||
testItem.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentBuilder shuffled = shuffleXContent(builder);
|
||||
XContentParser itemParser = XContentHelper.createParser(shuffled.bytes());
|
||||
XContentParser itemParser = createParser(shuffled);
|
||||
itemParser.nextToken();
|
||||
|
||||
/*
|
||||
|
|
|
@ -21,8 +21,8 @@ package org.elasticsearch.search.sort;
|
|||
|
||||
import org.apache.lucene.search.SortField;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
|
||||
|
@ -128,7 +128,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
|
|||
public void testReverseOptionFails() throws IOException {
|
||||
String json = "{ \"post_date\" : {\"reverse\" : true} },\n";
|
||||
|
||||
XContentParser parser = XContentFactory.xContent(json).createParser(json);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, json);
|
||||
// need to skip until parser is located on second START_OBJECT
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
|
|
@ -25,13 +25,12 @@ import org.apache.lucene.search.SortField;
|
|||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.geo.GeoDistance;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.unit.DistanceUnit;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.mapper.LatLonPointFieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.query.GeoValidationMethod;
|
||||
|
@ -206,7 +205,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
" } ],\n" +
|
||||
" \"reverse\" : true\n" +
|
||||
"}";
|
||||
XContentParser itemParser = XContentHelper.createParser(new BytesArray(json));
|
||||
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
|
||||
itemParser.nextToken();
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
|
||||
|
@ -227,7 +226,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
" } ],\n" +
|
||||
" \"reverse\" : \"true\"\n" +
|
||||
"}";
|
||||
XContentParser itemParser = XContentHelper.createParser(new BytesArray(json));
|
||||
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
|
||||
itemParser.nextToken();
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
|
||||
|
@ -244,7 +243,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
String json = "{\n" +
|
||||
" \"reverse\" : \"false\"\n" +
|
||||
"}";
|
||||
XContentParser itemParser = XContentHelper.createParser(new BytesArray(json));
|
||||
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
|
||||
itemParser.nextToken();
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
|
||||
|
@ -271,7 +270,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
" \"mode\" : \"SUM\",\n" +
|
||||
" \"coerce\" : true\n" +
|
||||
"}";
|
||||
XContentParser itemParser = XContentHelper.createParser(new BytesArray(json));
|
||||
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
|
||||
itemParser.nextToken();
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
|
||||
|
@ -292,7 +291,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
" \"mode\" : \"SUM\",\n" +
|
||||
" \"ignore_malformed\" : true\n" +
|
||||
"}";
|
||||
XContentParser itemParser = XContentHelper.createParser(new BytesArray(json));
|
||||
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
|
||||
itemParser.nextToken();
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
|
||||
|
@ -312,7 +311,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
" \"distance_type\" : \"sloppy_arc\",\n" +
|
||||
" \"mode\" : \"SUM\"\n" +
|
||||
"}";
|
||||
XContentParser itemParser = XContentHelper.createParser(new BytesArray(json));
|
||||
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
|
||||
itemParser.nextToken();
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
|
||||
|
@ -337,7 +336,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
" },\n" +
|
||||
" \"validation_method\" : \"STRICT\"\n" +
|
||||
" }";
|
||||
XContentParser itemParser = XContentHelper.createParser(new BytesArray(json));
|
||||
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
|
||||
itemParser.nextToken();
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
|
||||
|
@ -460,8 +459,8 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
assertEquals("Deprecated field [sort_mode] used, expected [mode] instead", ex.getMessage());
|
||||
}
|
||||
|
||||
private static GeoDistanceSortBuilder parse(XContentBuilder sortBuilder) throws Exception {
|
||||
XContentParser parser = XContentHelper.createParser(sortBuilder.bytes());
|
||||
private GeoDistanceSortBuilder parse(XContentBuilder sortBuilder) throws Exception {
|
||||
XContentParser parser = createParser(sortBuilder);
|
||||
QueryParseContext parseContext = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
|
||||
parser.nextToken();
|
||||
return GeoDistanceSortBuilder.fromXContent(parseContext, null);
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.search.SortField;
|
|||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
|
||||
|
@ -62,7 +63,7 @@ public class ScoreSortBuilderTests extends AbstractSortTestCase<ScoreSortBuilder
|
|||
public void testParseOrder() throws IOException {
|
||||
SortOrder order = randomBoolean() ? SortOrder.ASC : SortOrder.DESC;
|
||||
String scoreSortString = "{ \"_score\": { \"order\": \""+ order.toString() +"\" }}";
|
||||
XContentParser parser = XContentFactory.xContent(scoreSortString).createParser(scoreSortString);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, scoreSortString);
|
||||
// need to skip until parser is located on second START_OBJECT
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
@ -75,7 +76,7 @@ public class ScoreSortBuilderTests extends AbstractSortTestCase<ScoreSortBuilder
|
|||
|
||||
public void testReverseOptionFails() throws IOException {
|
||||
String json = "{ \"_score\": { \"reverse\": true }}";
|
||||
XContentParser parser = XContentFactory.xContent(json).createParser(json);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, json);
|
||||
// need to skip until parser is located on second START_OBJECT
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
|
|
@ -22,8 +22,8 @@ package org.elasticsearch.search.sort;
|
|||
|
||||
import org.apache.lucene.search.SortField;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
|
@ -167,7 +167,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
|||
"\"mode\" : \"max\",\n" +
|
||||
"\"order\" : \"asc\"\n" +
|
||||
"} }\n";
|
||||
XContentParser parser = XContentFactory.xContent(scriptSort).createParser(scriptSort);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, scriptSort);
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
@ -193,7 +193,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
|||
"\"mode\" : \"max\",\n" +
|
||||
"\"order\" : \"asc\"\n" +
|
||||
"} }\n";
|
||||
XContentParser parser = XContentFactory.xContent(scriptSort).createParser(scriptSort);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, scriptSort);
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
@ -213,7 +213,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
|||
|
||||
public void testParseBadFieldNameExceptions() throws IOException {
|
||||
String scriptSort = "{\"_script\" : {" + "\"bad_field\" : \"number\"" + "} }";
|
||||
XContentParser parser = XContentFactory.xContent(scriptSort).createParser(scriptSort);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, scriptSort);
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
@ -226,7 +226,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
|||
public void testParseBadFieldNameExceptionsOnStartObject() throws IOException {
|
||||
|
||||
String scriptSort = "{\"_script\" : {" + "\"bad_field\" : { \"order\" : \"asc\" } } }";
|
||||
XContentParser parser = XContentFactory.xContent(scriptSort).createParser(scriptSort);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, scriptSort);
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
@ -238,7 +238,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
|||
|
||||
public void testParseUnexpectedToken() throws IOException {
|
||||
String scriptSort = "{\"_script\" : {" + "\"script\" : [ \"order\" : \"asc\" ] } }";
|
||||
XContentParser parser = XContentFactory.xContent(scriptSort).createParser(scriptSort);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, scriptSort);
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
|
|
@ -20,15 +20,14 @@ x * Licensed to Elasticsearch under one or more contributor
|
|||
package org.elasticsearch.search.sort;
|
||||
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
|
@ -238,8 +237,8 @@ public class SortBuilderTests extends ESTestCase {
|
|||
assertEquals(new ScoreSortBuilder(), result.get(5));
|
||||
}
|
||||
|
||||
private static List<SortBuilder<?>> parseSort(String jsonString) throws IOException {
|
||||
XContentParser itemParser = XContentHelper.createParser(new BytesArray(jsonString));
|
||||
private List<SortBuilder<?>> parseSort(String jsonString) throws IOException {
|
||||
XContentParser itemParser = createParser(JsonXContent.jsonXContent, jsonString);
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT);
|
||||
|
||||
assertEquals(XContentParser.Token.START_OBJECT, itemParser.nextToken());
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
|
@ -128,7 +127,7 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
|
|||
xContentBuilder.endObject();
|
||||
|
||||
XContentBuilder shuffled = shuffleXContent(xContentBuilder, shuffleProtectedFields());
|
||||
XContentParser parser = XContentHelper.createParser(shuffled.bytes());
|
||||
XContentParser parser = createParser(shuffled);
|
||||
QueryParseContext context = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
// we need to skip the start object and the name, those will be parsed by outer SuggestBuilder
|
||||
parser.nextToken();
|
||||
|
@ -191,8 +190,7 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
|
|||
(Writeable.Reader<SB>) namedWriteableRegistry.getReader(SuggestionBuilder.class, original.getWriteableName()));
|
||||
}
|
||||
|
||||
protected static QueryParseContext newParseContext(final String xcontent) throws IOException {
|
||||
XContentParser parser = XContentFactory.xContent(xcontent).createParser(xcontent);
|
||||
protected static QueryParseContext newParseContext(XContentParser parser) throws IOException {
|
||||
final QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher);
|
||||
return parseContext;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class SuggestBuilderTests extends ESTestCase {
|
|||
xContentBuilder.prettyPrint();
|
||||
}
|
||||
suggestBuilder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
XContentParser parser = XContentHelper.createParser(xContentBuilder.bytes());
|
||||
XContentParser parser = createParser(xContentBuilder);
|
||||
QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
|
||||
SuggestBuilder secondSuggestBuilder = SuggestBuilder.fromXContent(context, suggesters);
|
||||
assertNotSame(suggestBuilder, secondSuggestBuilder);
|
||||
|
|
|
@ -50,8 +50,7 @@ public abstract class QueryContextTestCase<QC extends ToXContent> extends ESTest
|
|||
QC toXContent = createTestModel();
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
BytesReference bytesReference = builder.bytes();
|
||||
XContentParser parser = XContentFactory.xContent(bytesReference).createParser(bytesReference);
|
||||
XContentParser parser = createParser(builder);
|
||||
parser.nextToken();
|
||||
QC fromXContext = fromXContent(new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT));
|
||||
assertEquals(toXContent, fromXContext);
|
||||
|
|
|
@ -25,9 +25,9 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.search.suggest.phrase.PhraseSuggestionContext.DirectCandidateGenerator;
|
||||
|
@ -111,7 +111,7 @@ public class DirectCandidateGeneratorTests extends ESTestCase{
|
|||
builder.prettyPrint();
|
||||
}
|
||||
generator.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentParser parser = XContentHelper.createParser(shuffleXContent(builder).bytes());
|
||||
XContentParser parser = createParser(shuffleXContent(builder));
|
||||
QueryParseContext context = new QueryParseContext(mockRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
parser.nextToken();
|
||||
DirectCandidateGeneratorBuilder secondGenerator = DirectCandidateGeneratorBuilder.fromXContent(context);
|
||||
|
@ -169,9 +169,9 @@ public class DirectCandidateGeneratorTests extends ESTestCase{
|
|||
"[direct_generator] size doesn't support values of type: START_ARRAY");
|
||||
}
|
||||
|
||||
private static void assertIllegalXContent(String directGenerator, Class<? extends Exception> exceptionClass, String exceptionMsg)
|
||||
private void assertIllegalXContent(String directGenerator, Class<? extends Exception> exceptionClass, String exceptionMsg)
|
||||
throws IOException {
|
||||
XContentParser parser = XContentFactory.xContent(directGenerator).createParser(directGenerator);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, directGenerator);
|
||||
QueryParseContext context = new QueryParseContext(mockRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
Exception e = expectThrows(exceptionClass, () -> DirectCandidateGeneratorBuilder.fromXContent(context));
|
||||
assertEquals(exceptionMsg, e.getMessage());
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.elasticsearch.common.lucene.BytesRefs;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
|
@ -99,7 +98,7 @@ public abstract class SmoothingModelTestCase extends ESTestCase {
|
|||
contentBuilder.startObject();
|
||||
testModel.innerToXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
contentBuilder.endObject();
|
||||
XContentParser parser = XContentHelper.createParser(shuffleXContent(contentBuilder).bytes());
|
||||
XContentParser parser = createParser(shuffleXContent(contentBuilder));
|
||||
QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT);
|
||||
parser.nextToken(); // go to start token, real parsing would do that in the outer element parser
|
||||
SmoothingModel parsedModel = fromXContent(context);
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.elasticsearch.search.suggest.term;
|
|||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.search.suggest.AbstractSuggestionBuilderTestCase;
|
||||
import org.elasticsearch.search.suggest.DirectSpellcheckerSettings;
|
||||
import org.elasticsearch.search.suggest.SortBy;
|
||||
|
@ -215,8 +217,8 @@ public class TermSuggestionBuilderTests extends AbstractSuggestionBuilderTestCas
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
try {
|
||||
final SuggestBuilder suggestBuilder = SuggestBuilder.fromXContent(newParseContext(suggest), suggesters);
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, suggest)) {
|
||||
final SuggestBuilder suggestBuilder = SuggestBuilder.fromXContent(newParseContext(parser), suggesters);
|
||||
fail("Should not have been able to create SuggestBuilder from malformed JSON: " + suggestBuilder);
|
||||
} catch (Exception e) {
|
||||
assertThat(e.getMessage(), containsString("parsing failed"));
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -67,7 +66,7 @@ public class TaskResultTests extends ESTestCase {
|
|||
try (XContentBuilder builder = XContentBuilder.builder(randomFrom(XContentType.values()).xContent())) {
|
||||
result.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
try (XContentBuilder shuffled = shuffleXContent(builder);
|
||||
XContentParser parser = XContentHelper.createParser(shuffled.bytes())) {
|
||||
XContentParser parser = createParser(shuffled)) {
|
||||
read = TaskResult.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
|
@ -106,11 +107,7 @@ public class ThreadPoolSerializationTests extends ESTestCase {
|
|||
info.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
|
||||
BytesReference bytesReference = builder.bytes();
|
||||
Map<String, Object> map;
|
||||
try (XContentParser parser = XContentFactory.xContent(bytesReference).createParser(bytesReference)) {
|
||||
map = parser.map();
|
||||
}
|
||||
Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||
assertThat(map, hasKey("foo"));
|
||||
map = (Map<String, Object>) map.get("foo");
|
||||
assertThat(map, hasKey("queue_size"));
|
||||
|
|
|
@ -19,11 +19,12 @@
|
|||
package org.elasticsearch.script.mustache;
|
||||
|
||||
import com.github.mustachejava.MustacheFactory;
|
||||
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
|
@ -80,8 +81,12 @@ public class MustacheScriptEngineTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testSimple() throws IOException {
|
||||
String templateString = "{" + "\"inline\":{\"match_{{template}}\": {}}," + "\"params\":{\"template\":\"all\"}" + "}";
|
||||
XContentParser parser = XContentFactory.xContent(templateString).createParser(templateString);
|
||||
String templateString =
|
||||
"{"
|
||||
+ "\"inline\":{\"match_{{template}}\": {}},"
|
||||
+ "\"params\":{\"template\":\"all\"}"
|
||||
+ "}";
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, templateString);
|
||||
Script script = Script.parse(parser, new ParseFieldMatcher(false));
|
||||
CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, null, "mustache",
|
||||
qe.compile(null, script.getIdOrCode(), Collections.emptyMap()));
|
||||
|
@ -90,9 +95,14 @@ public class MustacheScriptEngineTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseTemplateAsSingleStringWithConditionalClause() throws IOException {
|
||||
String templateString = "{" + " \"inline\" : \"{ \\\"match_{{#use_it}}{{template}}{{/use_it}}\\\":{} }\"," + " \"params\":{"
|
||||
+ " \"template\":\"all\"," + " \"use_it\": true" + " }" + "}";
|
||||
XContentParser parser = XContentFactory.xContent(templateString).createParser(templateString);
|
||||
String templateString =
|
||||
"{"
|
||||
+ " \"inline\" : \"{ \\\"match_{{#use_it}}{{template}}{{/use_it}}\\\":{} }\"," + " \"params\":{"
|
||||
+ " \"template\":\"all\","
|
||||
+ " \"use_it\": true"
|
||||
+ " }"
|
||||
+ "}";
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, templateString);
|
||||
Script script = Script.parse(parser, new ParseFieldMatcher(false));
|
||||
CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, null, "mustache",
|
||||
qe.compile(null, script.getIdOrCode(), Collections.emptyMap()));
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.search.SearchRequest;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
@ -94,9 +94,13 @@ public class SearchTemplateIT extends ESSingleNodeTestCase {
|
|||
public void testTemplateQueryAsEscapedString() throws Exception {
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("_all");
|
||||
String query = "{" + " \"inline\" : \"{ \\\"size\\\": \\\"{{size}}\\\", \\\"query\\\":{\\\"match_all\\\":{}}}\","
|
||||
+ " \"params\":{" + " \"size\": 1" + " }" + "}";
|
||||
SearchTemplateRequest request = RestSearchTemplateAction.parse(XContentHelper.createParser(new BytesArray(query)));
|
||||
String query =
|
||||
"{" + " \"inline\" : \"{ \\\"size\\\": \\\"{{size}}\\\", \\\"query\\\":{\\\"match_all\\\":{}}}\","
|
||||
+ " \"params\":{"
|
||||
+ " \"size\": 1"
|
||||
+ " }"
|
||||
+ "}";
|
||||
SearchTemplateRequest request = RestSearchTemplateAction.parse(createParser(JsonXContent.jsonXContent, query));
|
||||
request.setRequest(searchRequest);
|
||||
SearchTemplateResponse searchResponse = client().execute(SearchTemplateAction.INSTANCE, request).get();
|
||||
assertThat(searchResponse.getResponse().getHits().hits().length, equalTo(1));
|
||||
|
@ -109,10 +113,15 @@ public class SearchTemplateIT extends ESSingleNodeTestCase {
|
|||
public void testTemplateQueryAsEscapedStringStartingWithConditionalClause() throws Exception {
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("_all");
|
||||
String templateString = "{"
|
||||
String templateString =
|
||||
"{"
|
||||
+ " \"inline\" : \"{ {{#use_size}} \\\"size\\\": \\\"{{size}}\\\", {{/use_size}} \\\"query\\\":{\\\"match_all\\\":{}}}\","
|
||||
+ " \"params\":{" + " \"size\": 1," + " \"use_size\": true" + " }" + "}";
|
||||
SearchTemplateRequest request = RestSearchTemplateAction.parse(XContentHelper.createParser(new BytesArray(templateString)));
|
||||
+ " \"params\":{"
|
||||
+ " \"size\": 1,"
|
||||
+ " \"use_size\": true"
|
||||
+ " }"
|
||||
+ "}";
|
||||
SearchTemplateRequest request = RestSearchTemplateAction.parse(createParser(JsonXContent.jsonXContent, templateString));
|
||||
request.setRequest(searchRequest);
|
||||
SearchTemplateResponse searchResponse = client().execute(SearchTemplateAction.INSTANCE, request).get();
|
||||
assertThat(searchResponse.getResponse().getHits().hits().length, equalTo(1));
|
||||
|
@ -125,10 +134,15 @@ public class SearchTemplateIT extends ESSingleNodeTestCase {
|
|||
public void testTemplateQueryAsEscapedStringWithConditionalClauseAtEnd() throws Exception {
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("_all");
|
||||
String templateString = "{"
|
||||
String templateString =
|
||||
"{"
|
||||
+ " \"inline\" : \"{ \\\"query\\\":{\\\"match_all\\\":{}} {{#use_size}}, \\\"size\\\": \\\"{{size}}\\\" {{/use_size}} }\","
|
||||
+ " \"params\":{" + " \"size\": 1," + " \"use_size\": true" + " }" + "}";
|
||||
SearchTemplateRequest request = RestSearchTemplateAction.parse(XContentHelper.createParser(new BytesArray(templateString)));
|
||||
+ " \"params\":{"
|
||||
+ " \"size\": 1,"
|
||||
+ " \"use_size\": true"
|
||||
+ " }"
|
||||
+ "}";
|
||||
SearchTemplateRequest request = RestSearchTemplateAction.parse(createParser(JsonXContent.jsonXContent, templateString));
|
||||
request.setRequest(searchRequest);
|
||||
SearchTemplateResponse searchResponse = client().execute(SearchTemplateAction.INSTANCE, request).get();
|
||||
assertThat(searchResponse.getResponse().getHits().hits().length, equalTo(1));
|
||||
|
|
|
@ -20,9 +20,8 @@
|
|||
package org.elasticsearch.script.mustache;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
|
@ -149,8 +148,8 @@ public class SearchTemplateRequestTests extends ESTestCase {
|
|||
/**
|
||||
* Creates a {@link XContentParser} with the given String while replacing single quote to double quotes.
|
||||
*/
|
||||
private static XContentParser newParser(String s) throws IOException {
|
||||
private XContentParser newParser(String s) throws IOException {
|
||||
assertNotNull(s);
|
||||
return XContentHelper.createParser(new BytesArray(s.replace("'", "\"")));
|
||||
return createParser(JsonXContent.jsonXContent, s.replace("'", "\""));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.percolator;
|
|||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.StreamsUtils;
|
||||
|
||||
|
@ -45,7 +46,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.onlyCount(), equalTo(false));
|
||||
assertThat(percolateRequest.getRequest(), nullValue());
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
Map sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
Map sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), equalTo((Object) MapBuilder.newMapBuilder().put("field1", "value1").map()));
|
||||
|
||||
percolateRequest = request.requests().get(1);
|
||||
|
@ -58,7 +59,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.onlyCount(), equalTo(false));
|
||||
assertThat(percolateRequest.getRequest(), nullValue());
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), equalTo((Object) MapBuilder.newMapBuilder().put("field1", "value2").map()));
|
||||
|
||||
percolateRequest = request.requests().get(2);
|
||||
|
@ -71,7 +72,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.onlyCount(), equalTo(true));
|
||||
assertThat(percolateRequest.getRequest(), nullValue());
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), equalTo((Object) MapBuilder.newMapBuilder().put("field1", "value3").map()));
|
||||
|
||||
percolateRequest = request.requests().get(3);
|
||||
|
@ -111,7 +112,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.onlyCount(), equalTo(false));
|
||||
assertThat(percolateRequest.getRequest(), nullValue());
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), equalTo((Object) MapBuilder.newMapBuilder().put("field1", "value4").map()));
|
||||
|
||||
percolateRequest = request.requests().get(6);
|
||||
|
@ -127,7 +128,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.indicesOptions(), equalTo(IndicesOptions.strictExpandOpenAndForbidClosed()));
|
||||
assertThat(percolateRequest.onlyCount(), equalTo(false));
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), nullValue());
|
||||
|
||||
percolateRequest = request.requests().get(7);
|
||||
|
@ -143,7 +144,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.indicesOptions(), equalTo(IndicesOptions.fromOptions(false, false, true, false, IndicesOptions.strictExpandOpenAndForbidClosed())));
|
||||
assertThat(percolateRequest.onlyCount(), equalTo(false));
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), nullValue());
|
||||
}
|
||||
|
||||
|
@ -163,7 +164,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.onlyCount(), equalTo(false));
|
||||
assertThat(percolateRequest.getRequest(), nullValue());
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
Map sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
Map sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), equalTo((Object) MapBuilder.newMapBuilder().put("field1", "value1").map()));
|
||||
|
||||
percolateRequest = request.requests().get(1);
|
||||
|
@ -175,7 +176,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.onlyCount(), equalTo(false));
|
||||
assertThat(percolateRequest.getRequest(), nullValue());
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), equalTo((Object) MapBuilder.newMapBuilder().put("field1", "value2").map()));
|
||||
|
||||
percolateRequest = request.requests().get(2);
|
||||
|
@ -185,7 +186,7 @@ public class MultiPercolatorRequestTests extends ESTestCase {
|
|||
assertThat(percolateRequest.onlyCount(), equalTo(false));
|
||||
assertThat(percolateRequest.getRequest(), nullValue());
|
||||
assertThat(percolateRequest.source(), notNullValue());
|
||||
sourceMap = XContentFactory.xContent(percolateRequest.source()).createParser(percolateRequest.source()).map();
|
||||
sourceMap = createParser(JsonXContent.jsonXContent, percolateRequest.source()).map();
|
||||
assertThat(sourceMap.get("doc"), equalTo((Object) MapBuilder.newMapBuilder().put("field1", "value3").map()));
|
||||
}
|
||||
|
||||
|
|
|
@ -475,8 +475,8 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
|
||||
private void assertQueryBuilder(BytesRef actual, QueryBuilder expected) throws IOException {
|
||||
XContentParser sourceParser = PercolatorFieldMapper.QUERY_BUILDER_CONTENT_TYPE.xContent()
|
||||
.createParser(actual.bytes, actual.offset, actual.length);
|
||||
XContentParser sourceParser = createParser(PercolatorFieldMapper.QUERY_BUILDER_CONTENT_TYPE.xContent(),
|
||||
new BytesArray(actual));
|
||||
QueryParseContext qsc = indexService.newQueryShardContext(
|
||||
randomInt(20), null, () -> { throw new UnsupportedOperationException(); })
|
||||
.newParseContext(sourceParser);
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
|||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
|
@ -425,7 +424,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
try (
|
||||
XContentGenerator generator = XContentType.JSON.xContent().createGenerator(out);
|
||||
XContentParser parser = XContentHelper.createParser(new BytesArray(query));
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(query);
|
||||
) {
|
||||
int objectIndex = -1;
|
||||
Deque<String> levels = new LinkedList<>();
|
||||
|
|
|
@ -70,9 +70,9 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|||
/**
|
||||
* Convert the entity from a {@link Response} into a map of maps.
|
||||
*/
|
||||
public static Map<String, Object> entityAsMap(Response response) throws IOException {
|
||||
public Map<String, Object> entityAsMap(Response response) throws IOException {
|
||||
XContentType xContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue());
|
||||
try (XContentParser parser = xContentType.xContent().createParser(response.getEntity().getContent())) {
|
||||
try (XContentParser parser = createParser(xContentType.xContent(), response.getEntity().getContent())) {
|
||||
return parser.map();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ESTestCaseTests extends ESTestCase {
|
|||
XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
|
||||
builder.map(randomStringObjectMap);
|
||||
XContentBuilder shuffleXContent = shuffleXContent(builder);
|
||||
XContentParser parser = XContentFactory.xContent(shuffleXContent.bytes()).createParser(shuffleXContent.bytes());
|
||||
XContentParser parser = createParser(shuffleXContent);
|
||||
Map<String, Object> resultMap = parser.map();
|
||||
assertEquals("both maps should contain the same mappings", randomStringObjectMap, resultMap);
|
||||
assertNotEquals("Both builders string representations should be different", builder.bytes(), shuffleXContent.bytes());
|
||||
|
|
Loading…
Reference in New Issue