From 7580d9d925d864b25466d693637b3bd3092d44cf Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Mon, 24 Dec 2018 14:06:50 -0500 Subject: [PATCH] Make SourceToParse immutable (#36971) Today the routing of a SourceToParse is assigned in a separate step after the object is created. We can easily forget to set the routing. With this commit, the routing must be provided in the constructor of SourceToParse. Relates #36921 --- .../painless/PainlessExecuteAction.java | 2 +- .../mapper/DenseVectorFieldMapperTests.java | 2 +- .../index/mapper/FeatureFieldMapperTests.java | 12 +- .../mapper/FeatureVectorFieldMapperTests.java | 6 +- .../mapper/ScaledFloatFieldMapperTests.java | 20 +-- .../mapper/SparseVectorFieldMapperTests.java | 10 +- .../mapper/TokenCountFieldMapperTests.java | 2 +- .../mapper/ParentJoinFieldMapperTests.java | 38 ++--- .../percolator/PercolateQueryBuilder.java | 4 +- .../PercolatorFieldMapperTests.java | 32 ++--- .../ICUCollationKeywordFieldMapperTests.java | 22 +-- .../AnnotatedTextFieldMapperTests.java | 18 +-- .../murmur3/Murmur3FieldMapperTests.java | 2 +- .../index/mapper/size/SizeMappingTests.java | 6 +- .../action/bulk/TransportShardBulkAction.java | 9 +- .../index/mapper/DocumentMapper.java | 4 +- .../index/mapper/SourceToParse.java | 24 ++-- .../elasticsearch/index/shard/IndexShard.java | 10 +- .../index/termvectors/TermVectorsService.java | 12 +- .../fielddata/BinaryDVFieldDataTests.java | 8 +- .../index/mapper/BinaryFieldMapperTests.java | 2 +- .../index/mapper/BooleanFieldMapperTests.java | 8 +- .../index/mapper/CamelCaseFieldNameTests.java | 2 +- .../mapper/CompletionFieldMapperTests.java | 44 +++--- .../index/mapper/CopyToMapperTests.java | 16 +-- .../index/mapper/DateFieldMapperTests.java | 24 ++-- .../index/mapper/DocumentMapperTests.java | 4 +- .../index/mapper/DocumentParserTests.java | 136 +++++++++--------- .../index/mapper/DoubleIndexingDocTests.java | 2 +- .../index/mapper/DynamicMappingTests.java | 24 ++-- .../mapper/DynamicMappingVersionTests.java | 2 +- .../index/mapper/DynamicTemplatesTests.java | 6 +- .../mapper/ExternalFieldMapperTests.java | 6 +- .../mapper/FieldNamesFieldMapperTests.java | 6 +- .../GenericStoreDynamicTemplateTests.java | 2 +- .../mapper/GeoPointFieldMapperTests.java | 56 ++++---- .../index/mapper/IdFieldMapperTests.java | 4 +- .../index/mapper/IndexFieldMapperTests.java | 2 +- .../index/mapper/IpFieldMapperTests.java | 16 +-- .../index/mapper/IpRangeFieldMapperTests.java | 2 +- .../mapper/JavaMultiFieldMergeTests.java | 8 +- .../index/mapper/KeywordFieldMapperTests.java | 24 ++-- .../index/mapper/MultiFieldTests.java | 4 +- .../index/mapper/NestedObjectMapperTests.java | 34 ++--- .../mapper/NullValueObjectMappingTests.java | 6 +- .../index/mapper/NumberFieldMapperTests.java | 24 ++-- .../index/mapper/ObjectMapperTests.java | 2 +- .../mapper/PathMatchDynamicTemplateTests.java | 2 +- .../index/mapper/RangeFieldMapperTests.java | 24 ++-- .../index/mapper/RoutingFieldMapperTests.java | 6 +- .../index/mapper/SourceFieldMapperTests.java | 10 +- .../mapper/StoredNumericValuesTests.java | 2 +- .../index/mapper/TextFieldMapperTests.java | 20 +-- .../index/mapper/TypeFieldMapperTests.java | 4 +- .../RecoveryDuringReplicationTests.java | 4 +- .../index/shard/IndexShardIT.java | 4 +- .../index/shard/IndexShardTests.java | 18 +-- .../shard/PrimaryReplicaSyncerTests.java | 4 +- .../indices/recovery/RecoveryTests.java | 18 +-- .../CategoryContextMappingTests.java | 18 +-- .../completion/GeoContextMappingTests.java | 8 +- .../index/engine/EngineTestCase.java | 2 +- .../index/engine/TranslogHandler.java | 7 +- .../index/shard/IndexShardTestCase.java | 4 +- .../engine/FollowEngineIndexShardTests.java | 4 +- .../SourceOnlySnapshotShardTests.java | 9 +- 66 files changed, 433 insertions(+), 444 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessExecuteAction.java index 5b120a8eba7..d8815ef9026 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessExecuteAction.java @@ -582,7 +582,7 @@ public class PainlessExecuteAction extends Action mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", Arrays.asList(10, 20)) @@ -155,7 +155,7 @@ public class FeatureFieldMapperTests extends ESSingleNodeTestCase { e.getCause().getMessage()); e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startArray("foo") diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureVectorFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureVectorFieldMapperTests.java index fccb62b1a34..852b6f6fc3c 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureVectorFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureVectorFieldMapperTests.java @@ -61,7 +61,7 @@ public class FeatureVectorFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") @@ -95,7 +95,7 @@ public class FeatureVectorFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") @@ -107,7 +107,7 @@ public class FeatureVectorFieldMapperTests extends ESSingleNodeTestCase { "START_ARRAY", e.getCause().getMessage()); e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startArray("foo") diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java index 67e0fad53ec..366f9a2e574 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java @@ -65,7 +65,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -115,7 +115,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -139,7 +139,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -163,7 +163,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -192,7 +192,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -216,7 +216,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper2.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -245,7 +245,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", value) @@ -261,7 +261,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", value) @@ -286,7 +286,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -308,7 +308,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/SparseVectorFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/SparseVectorFieldMapperTests.java index e805cf81bdf..06710e39592 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/SparseVectorFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/SparseVectorFieldMapperTests.java @@ -65,7 +65,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase { public void testDefaults() throws Exception { int[] indexedDims = {65535, 50, 2}; float[] indexedValues = {0.5f, 1800f, -34567.11f}; - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference + ParsedDocument doc1 = mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -103,7 +103,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase { public void testErrors() { // 1. test for an error on negative dimension MapperParsingException e = expectThrows(MapperParsingException.class, () -> { - mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference + mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -118,7 +118,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase { // 2. test for an error on a dimension greater than MAX_DIMS_NUMBER e = expectThrows(MapperParsingException.class, () -> { - mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference + mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -133,7 +133,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase { // 3. test for an error on a wrong formatted dimension e = expectThrows(MapperParsingException.class, () -> { - mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference + mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -148,7 +148,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase { // 4. test for an error on a wrong format for the map of dims to values e = expectThrows(MapperParsingException.class, () -> { - mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference + mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java index 34ad1934a3e..1965cbad066 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java @@ -192,7 +192,7 @@ public class TokenCountFieldMapperTests extends ESSingleNodeTestCase { .field("test", fieldValue) .endObject()); - return SourceToParse.source("test", "person", "1", request, XContentType.JSON); + return new SourceToParse("test", "person", "1", request, XContentType.JSON); } private ParseContext.Document parseDocument(DocumentMapper mapper, SourceToParse request) { diff --git a/modules/parent-join/src/test/java/org/elasticsearch/join/mapper/ParentJoinFieldMapperTests.java b/modules/parent-join/src/test/java/org/elasticsearch/join/mapper/ParentJoinFieldMapperTests.java index 97ca8900ea0..5c20969b53f 100644 --- a/modules/parent-join/src/test/java/org/elasticsearch/join/mapper/ParentJoinFieldMapperTests.java +++ b/modules/parent-join/src/test/java/org/elasticsearch/join/mapper/ParentJoinFieldMapperTests.java @@ -63,12 +63,12 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService())); // Doc without join - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)); assertNull(doc.rootDoc().getBinaryValue("join_field")); // Doc parent - doc = docMapper.parse(SourceToParse.source("test", "type", "1", + doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "parent") .endObject()), XContentType.JSON)); @@ -76,19 +76,19 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); // Doc child - doc = docMapper.parse(SourceToParse.source("test", "type", "2", + doc = docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", "1") .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON, "1")); assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); // Unkwnown join name MapperException exc = expectThrows(MapperParsingException.class, - () -> docMapper.parse(SourceToParse.source("test", "type", "1", + () -> docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "unknown") .endObject()), XContentType.JSON))); @@ -109,22 +109,22 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { IndexService service = createIndex("test"); DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "2", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", 1) .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON, "1")); assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); - doc = docMapper.parse(SourceToParse.source("test", "type", "2", + doc = docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", 1.0) .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON, "1")); assertEquals("1.0", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); } @@ -147,12 +147,12 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService())); // Doc without join - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)); assertNull(doc.rootDoc().getBinaryValue("join_field")); // Doc parent - doc = docMapper.parse(SourceToParse.source("test", "type", "1", + doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("join_field", "parent") @@ -161,28 +161,28 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); // Doc child - doc = docMapper.parse(SourceToParse.source("test", "type", "2", + doc = docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", "1") .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON, "1")); assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("2", doc.rootDoc().getBinaryValue("join_field#child").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); // Doc child missing parent MapperException exc = expectThrows(MapperParsingException.class, - () -> docMapper.parse(SourceToParse.source("test", "type", "2", + () -> docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "child") - .endObject()), XContentType.JSON).routing("1"))); + .endObject()), XContentType.JSON, "1"))); assertThat(exc.getRootCause().getMessage(), containsString("[parent] is missing for join field [join_field]")); // Doc child missing routing exc = expectThrows(MapperParsingException.class, - () -> docMapper.parse(SourceToParse.source("test", "type", "2", + () -> docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") @@ -192,19 +192,19 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { assertThat(exc.getRootCause().getMessage(), containsString("[routing] is missing for join field [join_field]")); // Doc grand_child - doc = docMapper.parse(SourceToParse.source("test", "type", "3", + doc = docMapper.parse(new SourceToParse("test", "type", "3", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "grand_child") .field("parent", "2") .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON, "1")); assertEquals("2", doc.rootDoc().getBinaryValue("join_field#child").utf8ToString()); assertEquals("grand_child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); // Unkwnown join name exc = expectThrows(MapperParsingException.class, - () -> docMapper.parse(SourceToParse.source("test", "type", "1", + () -> docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "unknown") .endObject()), XContentType.JSON))); diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java index 3c0076ea18f..2cb37cb794d 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java @@ -71,6 +71,7 @@ import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParsedDocument; +import org.elasticsearch.index.mapper.SourceToParse; import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryRewriteContext; @@ -89,7 +90,6 @@ import java.util.List; import java.util.Objects; import java.util.function.Supplier; -import static org.elasticsearch.index.mapper.SourceToParse.source; import static org.elasticsearch.percolator.PercolatorFieldMapper.parseQuery; public class PercolateQueryBuilder extends AbstractQueryBuilder { @@ -585,7 +585,7 @@ public class PercolateQueryBuilder extends AbstractQueryBuilder { - mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", BytesReference.bytes(XContentFactory + mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .field(fieldName, termQuery("unmapped_field", "value")) @@ -573,7 +573,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { public void testPercolatorFieldMapper_noQuery() throws Exception { addQueryFieldMappings(); - ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", BytesReference + ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference .bytes(XContentFactory .jsonBuilder() .startObject() @@ -582,7 +582,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getFields(fieldType.queryBuilderField.name()).length, equalTo(0)); try { - mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", BytesReference.bytes(XContentFactory + mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .nullField(fieldName) @@ -619,7 +619,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE); QueryBuilder queryBuilder = matchQuery("field", "value"); - ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", + ParsedDocument doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", BytesReference.bytes(jsonBuilder().startObject() .field("query_field1", queryBuilder) .field("query_field2", queryBuilder) @@ -650,7 +650,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE); QueryBuilder queryBuilder = matchQuery("field", "value"); - ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", + ParsedDocument doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", BytesReference.bytes(jsonBuilder().startObject().startObject("object_field") .field("query_field", queryBuilder) .endObject().endObject()), @@ -659,7 +659,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { BytesRef queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue(); assertQueryBuilder(queryBuilderAsBytes, queryBuilder); - doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", + doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", BytesReference.bytes(jsonBuilder().startObject() .startArray("object_field") .startObject().field("query_field", queryBuilder).endObject() @@ -671,7 +671,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { assertQueryBuilder(queryBuilderAsBytes, queryBuilder); MapperParsingException e = expectThrows(MapperParsingException.class, () -> { - mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", + mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", BytesReference.bytes(jsonBuilder().startObject() .startArray("object_field") .startObject().field("query_field", queryBuilder).endObject() @@ -756,7 +756,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { query.endObject(); query.endObject(); - ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", + ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType()) .endObject()), @@ -794,7 +794,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { query.endObject(); query.endObject(); - doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", + doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType()) .endObject()), @@ -880,7 +880,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { QueryBuilder qb = boolQuery() .must(boolQuery().must(termQuery("field", "value1")).must(termQuery("field", "value2"))) .must(boolQuery().must(termQuery("field", "value2")).must(termQuery("field", "value3"))); - ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", + ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), @@ -902,7 +902,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { .must(boolQuery().must(termQuery("field", "value2")).must(termQuery("field", "value3"))) .must(boolQuery().must(termQuery("field", "value3")).must(termQuery("field", "value4"))) .must(boolQuery().should(termQuery("field", "value4")).should(termQuery("field", "value5"))); - doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", + doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), @@ -927,7 +927,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { .should(boolQuery().should(termQuery("field", "value2")).should(termQuery("field", "value3"))) .should(boolQuery().should(termQuery("field", "value3")).should(termQuery("field", "value4"))) .should(boolQuery().should(termQuery("field", "value4")).should(termQuery("field", "value5"))); - doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", + doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java index f39ae886dc4..103098d5a46 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java @@ -72,7 +72,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -112,7 +112,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -129,7 +129,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .endObject()), @@ -138,7 +138,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -164,7 +164,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -186,7 +186,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -209,7 +209,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -230,7 +230,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", Arrays.asList("1234", "5678")) @@ -293,7 +293,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -326,7 +326,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -350,7 +350,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "I WİLL USE TURKİSH CASING") diff --git a/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java b/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java index 4156fd20672..aa0dbe07c83 100644 --- a/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java +++ b/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java @@ -116,7 +116,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { // Use example of typed and untyped annotations String annotatedText = "He paid [Stormy Daniels](Stephanie+Clifford&Payee) hush money"; - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", annotatedText) @@ -171,7 +171,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); String annotatedText = "foo [bar](MissingEndBracket baz"; - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", annotatedText) @@ -260,7 +260,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -292,7 +292,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -316,7 +316,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -347,7 +347,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { for (String option : supportedOptions.keySet()) { jsonDoc.field(option, "1234"); } - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(jsonDoc.endObject()), + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(jsonDoc.endObject()), XContentType.JSON)); for (Map.Entry entry : supportedOptions.entrySet()) { @@ -369,7 +369,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[] {"a", "b"}) @@ -411,7 +411,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[]{"a", "b"}) @@ -570,7 +570,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", "1234") diff --git a/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java b/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java index 1df613ab3f9..a26e2a48728 100644 --- a/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java +++ b/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java @@ -78,7 +78,7 @@ public class Murmur3FieldMapperTests extends ESSingleNodeTestCase { .field("type", "murmur3") .endObject().endObject().endObject().endObject()); DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument parsedDoc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDoc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java index dc143730264..58d9b696f6a 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java @@ -57,7 +57,7 @@ public class SizeMappingTests extends ESSingleNodeTestCase { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON)); boolean stored = false; boolean points = false; @@ -78,7 +78,7 @@ public class SizeMappingTests extends ESSingleNodeTestCase { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON)); assertThat(doc.rootDoc().getField("_size"), nullValue()); } @@ -92,7 +92,7 @@ public class SizeMappingTests extends ESSingleNodeTestCase { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON)); assertThat(doc.rootDoc().getField("_size"), nullValue()); } diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java index e04da71749f..d56cd5c8cbc 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -420,10 +420,8 @@ public class TransportShardBulkAction extends TransportWriteAction primary.applyIndexOperationOnPrimary(request.version(), request.versionType(), sourceToParse, diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java index cb962609fb4..058cf68e8e1 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java @@ -265,13 +265,13 @@ public class DocumentMapper implements ToXContentFragment { } public ParsedDocument createDeleteTombstoneDoc(String index, String type, String id) throws MapperParsingException { - final SourceToParse emptySource = SourceToParse.source(index, type, id, new BytesArray("{}"), XContentType.JSON); + final SourceToParse emptySource = new SourceToParse(index, type, id, new BytesArray("{}"), XContentType.JSON); return documentParser.parseDocument(emptySource, deleteTombstoneMetadataFieldMappers).toTombstone(); } public ParsedDocument createNoopTombstoneDoc(String index, String reason) throws MapperParsingException { final String id = ""; // _id won't be used. - final SourceToParse sourceToParse = SourceToParse.source(index, type, id, new BytesArray("{}"), XContentType.JSON); + final SourceToParse sourceToParse = new SourceToParse(index, type, id, new BytesArray("{}"), XContentType.JSON); final ParsedDocument parsedDoc = documentParser.parseDocument(sourceToParse, noopTombstoneMetadataFieldMappers).toTombstone(); // Store the reason of a noop as a raw string in the _source field final BytesRef byteRef = new BytesRef(reason); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java b/server/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java index 0130207c0a7..7cb3241d61f 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java @@ -21,17 +21,13 @@ package org.elasticsearch.index.mapper; import java.util.Objects; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentType; public class SourceToParse { - public static SourceToParse source(String index, String type, String id, BytesReference source, - XContentType contentType) { - return new SourceToParse(index, type, id, source, contentType); - } - private final BytesReference source; private final String index; @@ -40,11 +36,11 @@ public class SourceToParse { private final String id; - private String routing; + private final @Nullable String routing; - private XContentType xContentType; + private final XContentType xContentType; - private SourceToParse(String index, String type, String id, BytesReference source, XContentType xContentType) { + public SourceToParse(String index, String type, String id, BytesReference source, XContentType xContentType, @Nullable String routing) { this.index = Objects.requireNonNull(index); this.type = Objects.requireNonNull(type); this.id = Objects.requireNonNull(id); @@ -52,6 +48,11 @@ public class SourceToParse { // so, we might as well do it here, and improve the performance of working with direct byte arrays this.source = new BytesArray(Objects.requireNonNull(source).toBytesRef()); this.xContentType = Objects.requireNonNull(xContentType); + this.routing = routing; + } + + public SourceToParse(String index, String type, String id, BytesReference source, XContentType xContentType) { + this(index, type, id, source, xContentType, null); } public BytesReference source() { @@ -70,7 +71,7 @@ public class SourceToParse { return this.id; } - public String routing() { + public @Nullable String routing() { return this.routing; } @@ -78,11 +79,6 @@ public class SourceToParse { return this.xContentType; } - public SourceToParse routing(String routing) { - this.routing = routing; - return this; - } - public enum Origin { PRIMARY, REPLICA diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 37c7ace855c..06d9bb4018f 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -161,7 +161,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import static org.elasticsearch.index.mapper.SourceToParse.source; import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO; public class IndexShard extends AbstractIndexShardComponent implements IndicesClusterStateService.Shard { @@ -715,9 +714,8 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl if (resolvedType.equals(sourceToParse.type())) { sourceWithResolvedType = sourceToParse; } else { - sourceWithResolvedType = SourceToParse.source(sourceToParse.index(), resolvedType, sourceToParse.id(), - sourceToParse.source(), sourceToParse.getXContentType()); - sourceWithResolvedType.routing(sourceToParse.routing()); + sourceWithResolvedType = new SourceToParse(sourceToParse.index(), resolvedType, sourceToParse.id(), + sourceToParse.source(), sourceToParse.getXContentType(), sourceToParse.routing()); } operation = prepareIndex(docMapper(resolvedType), indexSettings.getIndexVersionCreated(), sourceWithResolvedType, seqNo, opPrimaryTerm, version, versionType, origin, autoGeneratedTimeStamp, isRetry, ifSeqNo, ifPrimaryTerm); @@ -1300,8 +1298,8 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl // autoGeneratedID docs that are coming from the primary are updated correctly. result = applyIndexOperation(engine, index.seqNo(), index.primaryTerm(), index.version(), versionType, UNASSIGNED_SEQ_NO, 0, index.getAutoGeneratedIdTimestamp(), true, origin, - source(shardId.getIndexName(), index.type(), index.id(), index.source(), - XContentHelper.xContentType(index.source())).routing(index.routing())); + new SourceToParse(shardId.getIndexName(), index.type(), index.id(), index.source(), + XContentHelper.xContentType(index.source()), index.routing())); break; case DELETE: final Translog.Delete delete = (Translog.Delete) operation; diff --git a/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java b/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java index 68f175f7ed6..a05870b842f 100644 --- a/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java +++ b/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java @@ -50,6 +50,7 @@ import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.SourceFieldMapper; +import org.elasticsearch.index.mapper.SourceToParse; import org.elasticsearch.index.mapper.StringFieldType; import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.shard.IndexShard; @@ -69,8 +70,6 @@ import java.util.TreeMap; import java.util.concurrent.TimeUnit; import java.util.function.LongSupplier; -import static org.elasticsearch.index.mapper.SourceToParse.source; - public class TermVectorsService { @@ -302,8 +301,8 @@ public class TermVectorsService { private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVectorsRequest request) throws IOException { // parse the document, at the moment we do update the mapping, just like percolate - ParsedDocument parsedDocument = - parseDocument(indexShard, indexShard.shardId().getIndexName(), request.type(), request.doc(), request.xContentType()); + ParsedDocument parsedDocument = parseDocument(indexShard, indexShard.shardId().getIndexName(), request.type(), request.doc(), + request.xContentType(), request.routing()); // select the right fields and generate term vectors ParseContext.Document doc = parsedDocument.rootDoc(); @@ -332,10 +331,11 @@ public class TermVectorsService { } private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc, - XContentType xContentType) { + XContentType xContentType, String routing) { MapperService mapperService = indexShard.mapperService(); DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type); - ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(source(index, type, "_id_for_tv_api", doc, xContentType)); + ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse( + new SourceToParse(index, type, "_id_for_tv_api", doc, xContentType, routing)); if (docMapper.getMapping() != null) { parsedDocument.addDynamicMappingsUpdate(docMapper.getMapping()); } diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/BinaryDVFieldDataTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/BinaryDVFieldDataTests.java index 3b29d15bf3f..023a0a84f53 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/BinaryDVFieldDataTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/BinaryDVFieldDataTests.java @@ -63,16 +63,16 @@ public class BinaryDVFieldDataTests extends AbstractFieldDataTestCase { doc.endArray(); } doc.endObject(); - ParsedDocument d = mapper.parse(SourceToParse.source("test", "test", "1", BytesReference.bytes(doc), XContentType.JSON)); + ParsedDocument d = mapper.parse(new SourceToParse("test", "test", "1", BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); BytesRef bytes1 = randomBytes(); doc = XContentFactory.jsonBuilder().startObject().field("field", bytes1.bytes, bytes1.offset, bytes1.length).endObject(); - d = mapper.parse(SourceToParse.source("test", "test", "2", BytesReference.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "test", "2", BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); doc = XContentFactory.jsonBuilder().startObject().endObject(); - d = mapper.parse(SourceToParse.source("test", "test", "3", BytesReference.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "test", "3", BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); // test remove duplicate value @@ -88,7 +88,7 @@ public class BinaryDVFieldDataTests extends AbstractFieldDataTestCase { doc.endArray(); } doc.endObject(); - d = mapper.parse(SourceToParse.source("test", "test", "4", BytesReference.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "test", "4", BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); IndexFieldData indexFieldData = getForField("field"); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java index 5f4cd98600b..3d8c348acab 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java @@ -91,7 +91,7 @@ public class BinaryFieldMapperTests extends ESSingleNodeTestCase { assertTrue(CompressorFactory.isCompressed(new BytesArray(binaryValue2))); for (byte[] value : Arrays.asList(binaryValue1, binaryValue2)) { - ParsedDocument doc = mapperService.documentMapper().parse(SourceToParse.source("test", "type", "id", + ParsedDocument doc = mapperService.documentMapper().parse(new SourceToParse("test", "type", "id", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), XContentType.JSON)); BytesRef indexedValue = doc.rootDoc().getBinaryValue("field"); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java index fd98a8199a2..f672a955cff 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java @@ -71,7 +71,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", true) @@ -141,7 +141,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase { .field("field", randomFrom("off", "no", "0", "on", "yes", "1")) .endObject()); MapperParsingException ex = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON))); + () -> defaultMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON))); assertEquals("failed to parse field [field] of type [boolean]", ex.getMessage()); } @@ -164,7 +164,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase { .startObject() .field("field", false) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON)); assertNotNull(doc.rootDoc().getField("field.as_string")); } @@ -187,7 +187,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); - ParsedDocument parsedDoc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument parsedDoc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("bool1", true) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java b/server/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java index 09394b39667..83aca847fa4 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java @@ -35,7 +35,7 @@ public class CamelCaseFieldNameTests extends ESSingleNodeTestCase { client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper documentMapper = index.mapperService().documentMapper("type"); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("thisIsCamelCase", "value1") .endObject()), diff --git a/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java index 513ba039c95..7354af17043 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java @@ -166,7 +166,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", "suggestion") @@ -187,7 +187,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { .parse("type1", new CompressedXContent(mapping)); MapperParsingException e = expectThrows(MapperParsingException.class, () -> - defaultMapper.parse(SourceToParse.source("test", "type1", "1", + defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", 1.0) @@ -220,7 +220,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("keywordfield", "key1", "key2", "key3") @@ -275,7 +275,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("suggest") @@ -331,7 +331,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("suggest", "timmy","starbucks") @@ -368,7 +368,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("geofield", "drm3btev3e86")//"41.12,-71.34" @@ -399,7 +399,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("suggest", "suggestion") @@ -431,7 +431,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") @@ -469,7 +469,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") @@ -509,7 +509,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", "suggestion") @@ -537,7 +537,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("completion", "suggestion1", "suggestion2") @@ -561,7 +561,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") @@ -587,7 +587,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") @@ -630,7 +630,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); Mapper fieldMapper = mapperService.documentMapper().mappers().getMapper("completion"); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") @@ -655,7 +655,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("completion") @@ -693,7 +693,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("completion") @@ -733,7 +733,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); try { - defaultMapper.parse(SourceToParse.source("test", "type1", "1", + defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field1") @@ -764,7 +764,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { charsRefBuilder.append("sugg"); charsRefBuilder.setCharAt(2, '\u001F'); try { - defaultMapper.parse(SourceToParse.source("test", "type1", "1", + defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) @@ -779,7 +779,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { charsRefBuilder.setCharAt(2, '\u0000'); try { - defaultMapper.parse(SourceToParse.source("test", "type1", "1", + defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) @@ -794,7 +794,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { charsRefBuilder.setCharAt(2, '\u001E'); try { - defaultMapper.parse(SourceToParse.source("test", "type1", "1", + defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) @@ -808,7 +808,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { } // empty inputs are ignored - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("completion", " ", "") @@ -821,7 +821,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase { assertThat(ignoredFields.stringValue(), equalTo("completion")); // null inputs are ignored - ParsedDocument nullDoc = defaultMapper.parse(SourceToParse.source("test", "type1", "1", + ParsedDocument nullDoc = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("completion") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java index 7936b97fad4..8a7a42e18f0 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java @@ -97,7 +97,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .field("int_to_str_test", 42) .endObject()); - ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)); + ParsedDocument parsedDoc = docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)); ParseContext.Document doc = parsedDoc.rootDoc(); assertThat(doc.getFields("copy_test").length, equalTo(2)); assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo")); @@ -153,7 +153,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .startObject("foo").startObject("bar").field("baz", "zoo").endObject().endObject() .endObject()); - ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, + ParseContext.Document doc = docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc(); assertThat(doc.getFields("copy_test").length, equalTo(1)); assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo")); @@ -181,7 +181,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .field("new_field", "bar") .endObject()); - ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, + ParseContext.Document doc = docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc(); assertThat(doc.getFields("copy_test").length, equalTo(1)); assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo")); @@ -219,7 +219,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .field("new_field", "bar") .endObject()); - ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, + ParseContext.Document doc = docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc(); assertThat(doc.getFields("copy_test").length, equalTo(1)); assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo")); @@ -250,7 +250,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc(); fail(); } catch (MapperParsingException ex) { assertThat(ex.getMessage(), startsWith("mapping set to strict, dynamic introduction of [very] within [type1] is not allowed")); @@ -285,7 +285,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc(); fail(); } catch (MapperParsingException ex) { assertThat(ex.getMessage(), @@ -393,7 +393,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endArray() .endObject(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(jsonDoc), XContentType.JSON)); assertEquals(6, doc.docs().size()); @@ -562,7 +562,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc(); fail(); } catch (MapperParsingException ex) { assertThat(ex.getMessage(), startsWith("It is forbidden to create dynamic nested objects ([very]) through `copy_to`")); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java index 023fa5ca051..8b437d25a84 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java @@ -66,7 +66,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-11") @@ -95,7 +95,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-11") @@ -117,7 +117,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-11") @@ -139,7 +139,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-11") @@ -166,7 +166,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-99") @@ -182,7 +182,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -204,7 +204,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 1457654400) @@ -230,7 +230,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { long epochMillis = randomNonNegativeLong(); String epochFloatValue = epochMillis + "." + randomIntBetween(0, 999); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", epochFloatValue) @@ -252,7 +252,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 1457654400) @@ -273,7 +273,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -294,7 +294,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -363,7 +363,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { final DateTimeZone randomTimeZone = randomBoolean() ? DateTimeZone.forID(randomFrom("UTC", "CET")) : randomDateTimeZone(); final DateTime randomDate = new DateTime(2016, 03, 11, 0, 0, 0, randomTimeZone); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", DateTimeFormat.forPattern(timeZonePattern).print(randomDate)) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java index 8cd39d72ad3..ff35e93204a 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java @@ -177,7 +177,7 @@ public class DocumentMapperTests extends ESSingleNodeTestCase { barrier.await(); for (int i = 0; i < 200 && stopped.get() == false; i++) { final String fieldName = Integer.toString(i); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "test", fieldName, new BytesArray("{ \"" + fieldName + "\" : \"test\" }"), @@ -200,7 +200,7 @@ public class DocumentMapperTests extends ESSingleNodeTestCase { while(stopped.get() == false) { final String fieldName = lastIntroducedFieldName.get(); final BytesReference source = new BytesArray("{ \"" + fieldName + "\" : \"test\" }"); - ParsedDocument parsedDoc = documentMapper.parse(SourceToParse.source("test", + ParsedDocument parsedDoc = documentMapper.parse(new SourceToParse("test", "test", "random", source, diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index 2ec49e5b204..ffdb93474c0 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -73,7 +73,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("foo", "1234") .field("bar", 10) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertNull(doc.rootDoc().getField("foo")); assertNotNull(doc.rootDoc().getField("bar")); assertNotNull(doc.rootDoc().getField(IdFieldMapper.NAME)); @@ -98,7 +98,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("baz", 789) .endObject() .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertNull(doc.dynamicMappingsUpdate()); // no update! String[] values = doc.rootDoc().getValues("foo.bar.baz"); assertEquals(3, values.length); @@ -120,7 +120,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("foo.bar", 123) .endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals( "Cannot add a value for field [foo.bar] since one of the intermediate objects is mapped as a nested object: [foo]", e.getMessage()); @@ -138,21 +138,21 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("foo", true) .endObject()); MapperException exception = expectThrows(MapperException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertThat(exception.getMessage(), containsString("failed to parse field [foo] of type [long]")); } { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("bar", "bar") .endObject()); MapperException exception = expectThrows(MapperException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "2", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "2", bytes, XContentType.JSON))); assertThat(exception.getMessage(), containsString("failed to parse field [bar] of type [boolean]")); } { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("geo", 123) .endObject()); MapperException exception = expectThrows(MapperException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "2", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "2", bytes, XContentType.JSON))); assertThat(exception.getMessage(), containsString("failed to parse field [geo] of type [geo_shape]")); } @@ -178,7 +178,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("foo.bar",42) .endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals( "It is forbidden to create dynamic nested objects ([foo]) through `copy_to` or dots in field names", e.getMessage()); @@ -225,7 +225,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { doc.endObject(); // Verify in the case where only a single type is allowed that the _id field is added to nested documents: - ParsedDocument result = mapper.parse(SourceToParse.source("index2", "type", "1", + ParsedDocument result = mapper.parse(new SourceToParse("index2", "type", "1", BytesReference.bytes(doc), XContentType.JSON)); assertEquals(2, result.docs().size()); // Nested document: @@ -258,7 +258,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().startObject("foo") .field("bar", "something") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertNotNull(doc.dynamicMappingsUpdate()); assertNotNull(doc.rootDoc().getField("foo.bar")); } @@ -278,7 +278,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().startObject("foo").startObject("bar") .field("baz", "something") .endObject().endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertNotNull(doc.dynamicMappingsUpdate()); assertNotNull(doc.rootDoc().getField("foo.bar.baz")); } @@ -297,7 +297,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().startObject("foo") .field("bar", "something") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertNull(doc.dynamicMappingsUpdate()); assertNull(doc.rootDoc().getField("foo.bar")); } @@ -428,7 +428,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startArray().value(0).value(0).endArray() .startArray().value(1).value(1).endArray() .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo").length); } @@ -446,7 +446,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -461,7 +461,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -477,7 +477,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo").length); } @@ -494,7 +494,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(1) .endArray().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -511,7 +511,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startArray().value(0).value(0).endArray() .startArray().value(1).value(1).endArray() .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo").length); } @@ -527,7 +527,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -545,7 +545,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().startObject("foo") .field("bar", "baz") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo.bar").length); } @@ -560,7 +560,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().startObject("foo") .field("bar", "baz") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo.bar").length); } @@ -576,7 +576,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("bar", "baz") .endObject().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -591,7 +591,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject() .field("bar", "baz") .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("bar").length); } @@ -607,7 +607,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("bar", "baz") .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); } @@ -622,7 +622,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject() .field("bar", (String) null) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("bar").length); } @@ -638,7 +638,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("bar", (String) null) .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); } @@ -652,7 +652,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo", (Long) null) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo").length); } @@ -667,7 +667,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -694,7 +694,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -720,7 +720,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -747,7 +747,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(1) .endArray().endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. " + "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage()); } @@ -764,7 +764,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length); } @@ -781,7 +781,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .value(1) .endArray().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -794,7 +794,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -819,7 +819,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -843,7 +843,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -868,7 +868,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().field("foo.bar.baz", 0) .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. " + "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage()); } @@ -883,7 +883,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length); } @@ -898,7 +898,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().field("foo.bar.baz", 0) .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -912,7 +912,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -941,7 +941,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -965,7 +965,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz") .field("a", 0).endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -992,7 +992,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz") .field("a", 0).endObject().endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. " + "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage()); @@ -1009,7 +1009,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz.a").length); } @@ -1025,7 +1025,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("a", 0) .endObject().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -1036,12 +1036,12 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("_ttl", 0).endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, () -> - mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertTrue(e.getMessage(), e.getMessage().contains("cannot be added inside a document")); BytesReference bytes2 = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("foo._ttl", 0).endObject()); - mapper.parse(SourceToParse.source("test", "type", "1", bytes2, XContentType.JSON)); // parses without error + mapper.parse(new SourceToParse("test", "type", "1", bytes2, XContentType.JSON)); // parses without error } public void testSimpleMapper() throws Exception { @@ -1053,10 +1053,10 @@ public class DocumentParserTests extends ESSingleNodeTestCase { indexService.mapperService()).build(indexService.mapperService()); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); assertThat(doc.get(docMapper.mappers().getMapper("name.first").name()), equalTo("shay")); - doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); } public void testParseToJsonAndParse() throws Exception { @@ -1067,7 +1067,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { // reparse it DocumentMapper builtDocMapper = parser.parse("person", new CompressedXContent(builtMapping)); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json")); - Document doc = builtDocMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = builtDocMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); assertThat(doc.getBinaryValue(docMapper.idFieldMapper().name()), equalTo(Uid.encodeId("1"))); assertThat(doc.get(docMapper.mappers().getMapper("name.first").name()), equalTo("shay")); } @@ -1080,7 +1080,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { assertThat((String) docMapper.meta().get("param1"), equalTo("value1")); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); assertThat(doc.getBinaryValue(docMapper.idFieldMapper().name()), equalTo(Uid.encodeId("1"))); assertThat(doc.get(docMapper.mappers().getMapper("name.first").name()), equalTo("shay")); } @@ -1090,7 +1090,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("person", new CompressedXContent(mapping)); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1-notype-noid.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); assertThat(doc.getBinaryValue(docMapper.idFieldMapper().name()), equalTo(Uid.encodeId("1"))); assertThat(doc.get(docMapper.mappers().getMapper("name.first").name()), equalTo("shay")); } @@ -1117,7 +1117,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { BytesReference json = new BytesArray("".getBytes(StandardCharsets.UTF_8)); try { - docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); fail("this point is never reached"); } catch (MapperParsingException e) { assertThat(e.getMessage(), equalTo("failed to parse, document is empty")); @@ -1130,7 +1130,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("test1", "value1") @@ -1150,7 +1150,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("test1", "value1") @@ -1170,7 +1170,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("type", "value_type") @@ -1192,7 +1192,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("type", "value_type") @@ -1214,7 +1214,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("type").field("type_field", "type_value").endObject() @@ -1236,7 +1236,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .startObject("type").field("type_field", "type_value").endObject() @@ -1258,7 +1258,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("test1", "value1") @@ -1280,7 +1280,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("test1", "value1") @@ -1302,7 +1302,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("test1", "value1") @@ -1325,7 +1325,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("test1", "value1") @@ -1356,7 +1356,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { // Even though we matched the dynamic format, we do not match on numbers, // which are too likely to be false positives - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); Mapping update = doc.dynamicMappingsUpdate(); assertNotNull(update); Mapper dateMapper = update.root().getMapper("foo"); @@ -1378,7 +1378,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .endObject()); // We should have generated a date field - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); Mapping update = doc.dynamicMappingsUpdate(); assertNotNull(update); Mapper dateMapper = update.root().getMapper("foo"); @@ -1481,7 +1481,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("alias-field", "value") .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("Cannot write to a field alias [alias-field].", exception.getCause().getMessage()); } @@ -1514,7 +1514,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("text-field", "value") .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("Cannot copy to a field alias [alias-field].", exception.getCause().getMessage()); } @@ -1545,7 +1545,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .endObject() .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON))); assertEquals("Could not dynamically add mapping for field [alias-field.dynamic-field]. " + "Existing mapping for [alias-field] must be of type object but found [alias].", exception.getMessage()); @@ -1564,7 +1564,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("foo", "1234") .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "_doc", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "_doc", "1", bytes, XContentType.JSON)); assertNull(doc.dynamicMappingsUpdate()); // no update since we reused the existing type } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java index 23e205b8f58..2eea666e8fe 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java @@ -50,7 +50,7 @@ public class DoubleIndexingDocTests extends ESSingleNodeTestCase { QueryShardContext context = index.newQueryShardContext(0, null, () -> 0L, null); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", "value1") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java index 8fc03a49c85..56e6f5e4c6b 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java @@ -70,7 +70,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(jsonBuilder() .startObject() .field("field1", "value1") @@ -93,7 +93,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(jsonBuilder() .startObject() .field("field1", "value1") @@ -118,7 +118,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .parse("type", new CompressedXContent(mapping)); StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", + () -> defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(jsonBuilder() .startObject() .field("field1", "value1") @@ -128,7 +128,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed")); e = expectThrows(StrictDynamicMappingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", + () -> defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", "value1") @@ -151,7 +151,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(jsonBuilder() .startObject().startObject("obj1") .field("field1", "value1") @@ -178,7 +178,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .parse("type", new CompressedXContent(mapping)); StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () -> - defaultMapper.parse(SourceToParse.source("test", "type", "1", + defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(jsonBuilder() .startObject().startObject("obj1") .field("field1", "value1") @@ -207,7 +207,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .settings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)) .numberOfShards(1).numberOfReplicas(0).build(); IndexSettings settings = new IndexSettings(build, Settings.EMPTY); - SourceToParse source = SourceToParse.source("test", mapper.type(), "some_id", + SourceToParse source = new SourceToParse("test", mapper.type(), "some_id", BytesReference.bytes(builder), builder.contentType()); try (XContentParser xContentParser = createParser(JsonXContent.jsonXContent, source.source())) { ParseContext.InternalParseContext ctx = new ParseContext.InternalParseContext(settings, parser, mapper, source, xContentParser); @@ -561,7 +561,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { XContentBuilder json = XContentFactory.jsonBuilder().startObject() .field("field", "foo") .endObject(); - SourceToParse source = SourceToParse.source("test", "_doc", "1", BytesReference.bytes(json), json.contentType()); + SourceToParse source = new SourceToParse("test", "_doc", "1", BytesReference.bytes(json), json.contentType()); DocumentMapper mapper = indexService.mapperService().documentMapper("_doc"); assertNull(mapper.mappers().getMapper("field.raw")); ParsedDocument parsed = mapper.parse(source); @@ -596,7 +596,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .field("baz", (double) 3.2f) // double that can be accurately represented as a float .field("quux", "3.2") // float detected through numeric detection .endObject()); - ParsedDocument parsedDocument = mapper.parse(SourceToParse.source("index", "type", "id", + ParsedDocument parsedDocument = mapper.parse(new SourceToParse("index", "type", "id", source, builder.contentType())); Mapping update = parsedDocument.dynamicMappingsUpdate(); assertNotNull(update); @@ -615,7 +615,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper defaultMapper = index.mapperService().documentMapper("type"); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("s_long", "100") @@ -642,7 +642,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper defaultMapper = index.mapperService().documentMapper("type"); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("s_long", "100") @@ -691,7 +691,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper defaultMapper = index.mapperService().documentMapper("type"); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("date1", "2016-11-20") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java index fba85b1909c..6b451b64db0 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java @@ -45,7 +45,7 @@ public class DynamicMappingVersionTests extends ESSingleNodeTestCase { .documentMapperWithAutoCreate("my-type").getDocumentMapper(); ParsedDocument parsedDoc = documentMapper.parse( - SourceToParse.source("my-index", "my-type", "1", BytesReference + new SourceToParse("my-index", "my-type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("foo", 3) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java index 62c764e8060..ff44dec81d9 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java @@ -50,7 +50,7 @@ public class DynamicTemplatesTests extends ESSingleNodeTestCase { DocumentMapper docMapper = mapperService.documentMapper("person"); builder = JsonXContent.contentBuilder(); builder.startObject().field("s", "hello").field("l", 1).endObject(); - ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", BytesReference.bytes(builder), + ParsedDocument parsedDoc = docMapper.parse(new SourceToParse("test", "person", "1", BytesReference.bytes(builder), XContentType.JSON)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); @@ -70,7 +70,7 @@ public class DynamicTemplatesTests extends ESSingleNodeTestCase { client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get(); DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json"); - ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json), + ParsedDocument parsedDoc = docMapper.parse(new SourceToParse("test", "person", "1", new BytesArray(json), XContentType.JSON)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); @@ -129,7 +129,7 @@ public class DynamicTemplatesTests extends ESSingleNodeTestCase { client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get(); DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json"); - ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json), + ParsedDocument parsedDoc = docMapper.parse(new SourceToParse("test", "person", "1", new BytesArray(json), XContentType.JSON)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java index 1d65fb27c55..e2f9f798a14 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java @@ -87,7 +87,7 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject()) )); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -146,7 +146,7 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().endObject()))); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -213,7 +213,7 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().endObject()))); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java index 6d7601357a3..d0d4a6b1d15 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java @@ -82,7 +82,7 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("a", "100") @@ -106,7 +106,7 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase { FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class); assertTrue(fieldNamesMapper.fieldType().isEnabled()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -125,7 +125,7 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase { FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class); assertFalse(fieldNamesMapper.fieldType().isEnabled()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java b/server/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java index 6999e39b70a..e67469bcd85 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java @@ -40,7 +40,7 @@ public class GenericStoreDynamicTemplateTests extends ESSingleNodeTestCase { byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-data.json"); ParsedDocument parsedDoc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", new BytesArray(json), XContentType.JSON)); + new SourceToParse("test", "person", "1", new BytesArray(json), XContentType.JSON)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); Document doc = parsedDoc.rootDoc(); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java index a2c17e68b78..f5597ecb1f4 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java @@ -65,7 +65,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", stringEncode(1.3, 1.2)) @@ -82,7 +82,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("point").field("lat", 1.2).field("lon", 1.3).endObject() @@ -99,7 +99,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") @@ -121,7 +121,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3") @@ -139,7 +139,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3,10.0") @@ -157,7 +157,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - SourceToParse source = SourceToParse.source("test", "type", "1", + SourceToParse source = new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3,10.0") @@ -175,7 +175,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3") @@ -191,7 +191,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") @@ -213,7 +213,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() @@ -231,7 +231,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() @@ -248,7 +248,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() @@ -268,7 +268,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") @@ -381,7 +381,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { Object nullValue = ((GeoPointFieldMapper) fieldMapper).fieldType().nullValue(); assertThat(nullValue, equalTo(new GeoPoint(1, 2))); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("location") @@ -391,7 +391,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("location"), notNullValue()); BytesRef defaultValue = doc.rootDoc().getField("location").binaryValue(); - doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1, 2") @@ -400,7 +400,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { // Shouldn't matter if we specify the value explicitly or use null value assertThat(defaultValue, equalTo(doc.rootDoc().getField("location").binaryValue())); - doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "3, 4") @@ -422,7 +422,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1234.333") @@ -445,7 +445,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { .parse("type", new CompressedXContent(mapping)); MapperParsingException ex = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", + () -> defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1234.333") @@ -469,57 +469,57 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "1234.333").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("lat", "-").field("lon", 1.3).endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("lat", 1.3).field("lon", "-").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "-,1.3").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "1.3,-").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("lat", "NaN").field("lon", "NaN").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("lat", 12).field("lon", "NaN").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("lat", "NaN").field("lon", 10).endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "NaN,NaN").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "10,NaN").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", + assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "NaN,12").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java index aab5e98ed0a..f015dee1f89 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java @@ -50,7 +50,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase { .parse("type", new CompressedXContent(mapping)); try { - docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("_id", "1").endObject()), XContentType.JSON)); fail("Expected failure to parse metadata field"); } catch (MapperParsingException e) { @@ -62,7 +62,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase { Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", + ParsedDocument document = mapper.parse(new SourceToParse("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); IndexableField[] fields = document.rootDoc().getFields(IdFieldMapper.NAME); assertEquals(1, fields.length); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java index e60b097aaca..7fd867f9b34 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java @@ -47,7 +47,7 @@ public class IndexFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java index c5eded8f5ab..6396b3988bc 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java @@ -68,7 +68,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -97,7 +97,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -119,7 +119,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -142,7 +142,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -170,7 +170,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -185,7 +185,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -210,7 +210,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -231,7 +231,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IpRangeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IpRangeFieldMapperTests.java index 2c70b25d6a4..9b126da4c2b 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IpRangeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IpRangeFieldMapperTests.java @@ -60,7 +60,7 @@ public class IpRangeFieldMapperTests extends ESSingleNodeTestCase { cases.put("192.168.0.0/17", "192.168.127.255"); for (final Map.Entry entry : cases.entrySet()) { ParsedDocument doc = - mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", entry.getKey()) .endObject()), diff --git a/server/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java index 8060c0a3f92..fba695ba86c 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java @@ -45,7 +45,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); Document doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -61,7 +61,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { assertThat(mapperService.fullName("name.not_indexed2"), nullValue()); assertThat(mapperService.fullName("name.not_indexed3"), nullValue()); - doc = mapperService.documentMapper().parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + doc = mapperService.documentMapper().parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -99,7 +99,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); Document doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -117,7 +117,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { assertThat(mapperService.fullName("name.not_indexed3"), nullValue()); doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java index 8e5c81e58f1..d7f8d48fc5c 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java @@ -110,7 +110,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -147,7 +147,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "elk") @@ -157,7 +157,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "elasticsearch") @@ -176,7 +176,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -192,7 +192,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .endObject()), @@ -201,7 +201,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -222,7 +222,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -243,7 +243,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -265,7 +265,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -287,7 +287,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -333,7 +333,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -358,7 +358,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "AbC") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java index 8e350cfe1c7..6bd0b608f3f 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java @@ -64,7 +64,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase { BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json")); Document doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f.name(), equalTo("name")); @@ -140,7 +140,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase { BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f.name(), equalTo("name")); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java index 1d339aa9bbb..d3f41589fb1 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java @@ -63,7 +63,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -73,7 +73,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { assertThat(doc.docs().size(), equalTo(1)); - doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -96,7 +96,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1"); assertThat(nested1Mapper.nested().isNested(), equalTo(true)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -112,7 +112,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { assertThat(doc.docs().get(1).get("field"), equalTo("value")); - doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -154,7 +154,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false)); assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -215,7 +215,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true)); assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -278,7 +278,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true)); assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -339,7 +339,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false)); assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(true)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -398,7 +398,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().startArray("nested1") .startObject().startArray("nested2").startObject().field("foo", "bar") @@ -432,7 +432,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().startArray("nested1") .startObject().startArray("nested2") @@ -460,7 +460,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { assertThat(nested1Mapper.nested().isNested(), equalTo(true)); assertThat(nested1Mapper.dynamic(), equalTo(Dynamic.STRICT)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -568,7 +568,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = SourceToParse.source("test1", "type", "1", + SourceToParse source1 = new SourceToParse("test1", "type", "1", BytesReference.bytes(docBuilder), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source1)); assertEquals( @@ -601,7 +601,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = SourceToParse.source("test1", "type", "1", + SourceToParse source1 = new SourceToParse("test1", "type", "1", BytesReference.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -619,7 +619,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { docBuilder2.endArray(); } docBuilder2.endObject(); - SourceToParse source2 = SourceToParse.source("test1", "type", "2", + SourceToParse source2 = new SourceToParse("test1", "type", "2", BytesReference.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( @@ -657,7 +657,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = SourceToParse.source("test1", "type", "1", + SourceToParse source1 = new SourceToParse("test1", "type", "1", BytesReference.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -680,7 +680,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { } docBuilder2.endObject(); - SourceToParse source2 = SourceToParse.source("test1", "type", "2", + SourceToParse source2 = new SourceToParse("test1", "type", "2", BytesReference.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( @@ -714,7 +714,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1"); assertThat(nested1Mapper.nested().isNested(), equalTo(true)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java b/server/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java index 550802f6c9d..85922fccff8 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java @@ -39,7 +39,7 @@ public class NullValueObjectMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("obj1").endObject() @@ -49,7 +49,7 @@ public class NullValueObjectMappingTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().get("value1"), equalTo("test1")); - doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("obj1") @@ -59,7 +59,7 @@ public class NullValueObjectMappingTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().get("value1"), equalTo("test1")); - doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", + doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("obj1").field("field", "value").endObject() diff --git a/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java index 8b8e174dba8..ba7f5d84684 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java @@ -56,7 +56,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -84,7 +84,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -107,7 +107,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -131,7 +131,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -160,7 +160,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -183,7 +183,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(mapping, mapper2.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -203,7 +203,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "7.89") @@ -230,7 +230,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "a") @@ -246,7 +246,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "a") @@ -308,7 +308,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -335,7 +335,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -422,7 +422,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { } private void parseRequest(NumberType type, BytesReference content) throws IOException { - createDocumentMapper(type).parse(SourceToParse.source("test", "type", "1", content, XContentType.JSON)); + createDocumentMapper(type).parse(new SourceToParse("test", "type", "1", content, XContentType.JSON)); } private DocumentMapper createDocumentMapper(NumberType type) throws IOException { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java index 676cefda365..db3feee39e0 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java @@ -43,7 +43,7 @@ public class ObjectMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { - defaultMapper.parse(SourceToParse.source("test", "type", "1", new BytesArray(" {\n" + + defaultMapper.parse(new SourceToParse("test", "type", "1", new BytesArray(" {\n" + " \"object\": {\n" + " \"array\":[\n" + " {\n" + diff --git a/server/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java b/server/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java index 9546fb5136e..31cfd5e82ee 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java @@ -40,7 +40,7 @@ public class PathMatchDynamicTemplateTests extends ESSingleNodeTestCase { byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json"); ParsedDocument parsedDoc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", new BytesArray(json), XContentType.JSON)); + new SourceToParse("test", "person", "1", new BytesArray(json), XContentType.JSON)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); Document doc = parsedDoc.rootDoc(); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java index 1f8b0b58af8..fcb78f66add 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java @@ -121,7 +121,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -152,7 +152,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -176,7 +176,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -202,7 +202,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -241,7 +241,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -267,7 +267,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(Strings.toString(mapping), mapper2.mappingSource().toString()); ThrowingRunnable runnable = () -> mapper2 - .parse(SourceToParse.source( + .parse(new SourceToParse( "test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("field") .field(getFromField(), "5.2").field(getToField(), "10").endObject().endObject()), XContentType.JSON)); @@ -287,7 +287,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(GT_FIELD.getPreferredName(), "2.34") @@ -296,7 +296,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { .endObject()), XContentType.JSON)); - ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc2 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(GT_FIELD.getPreferredName(), "2") @@ -324,7 +324,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); // test null value for min and max - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .nullField(getFromField()) @@ -339,7 +339,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertThat(storedField.stringValue(), containsString(expected)); // test null max value - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -367,7 +367,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertThat(storedField.stringValue(), containsString(strVal)); // test null range - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -394,7 +394,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); // test no bounds specified - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .endObject() diff --git a/server/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java index 11c858545d0..3da00e3f787 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java @@ -37,12 +37,12 @@ public class RoutingFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), - XContentType.JSON).routing("routing_value")); + XContentType.JSON, "routing_value")); assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value")); assertThat(doc.rootDoc().get("field"), equalTo("value")); @@ -54,7 +54,7 @@ public class RoutingFieldMapperTests extends ESSingleNodeTestCase { .parse("type", new CompressedXContent(mapping)); try { - docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("_routing", "foo").endObject()),XContentType.JSON)); fail("Expected failure to parse metadata field"); } catch (MapperParsingException e) { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java index baccb4f474e..a8db41e677b 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java @@ -54,7 +54,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase { DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("field", "value") .endObject()), @@ -63,7 +63,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase { assertThat(XContentFactory.xContentType(doc.source().toBytesRef().bytes), equalTo(XContentType.JSON)); documentMapper = parser.parse("type", new CompressedXContent(mapping)); - doc = documentMapper.parse(SourceToParse.source("test", "type", "1", + doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.smileBuilder().startObject() .field("field", "value") .endObject()), @@ -80,7 +80,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("path1").field("field1", "value1").endObject() .startObject("path2").field("field2", "value2").endObject() @@ -104,7 +104,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("path1").field("field1", "value1").endObject() .startObject("path2").field("field2", "value2").endObject() @@ -216,7 +216,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase { .parse("type", new CompressedXContent(mapping)); try { - documentMapper.parse(SourceToParse.source("test", "type", "1", + documentMapper.parse(new SourceToParse("test", "type", "1", new BytesArray("{}}"), XContentType.JSON)); // extra end object (invalid JSON) fail("Expected parse exception"); } catch (MapperParsingException e) { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java b/server/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java index a07192df804..1b279f4d268 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java @@ -64,7 +64,7 @@ public class StoredNumericValuesTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test").mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", 1) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java index f149620b028..acd6c9ee6f8 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java @@ -103,7 +103,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -135,7 +135,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -156,7 +156,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -179,7 +179,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -210,7 +210,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { for (String option : supportedOptions.keySet()) { jsonDoc.field(option, "1234"); } - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(jsonDoc.endObject()), + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(jsonDoc.endObject()), XContentType.JSON)); for (Map.Entry entry : supportedOptions.entrySet()) { @@ -232,7 +232,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[] {"a", "b"}) @@ -274,7 +274,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[]{"a", "b"}) @@ -433,7 +433,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", "1234") @@ -765,7 +765,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { new Term("synfield._index_phrase", "motor dog")}) .build())); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "Some English text that is going to be very useful") @@ -830,7 +830,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { assertThat(mapper.mappers().getMapper("field._index_prefix").toString(), containsString("prefixChars=2:10")); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "Some English text that is going to be very useful") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java index 26f2b7fc923..c763040d01d 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java @@ -59,7 +59,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase { public static void testDocValues(Function createIndex) throws IOException { MapperService mapperService = createIndex.apply("test").mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(new SourceToParse("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig()); @@ -84,7 +84,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase { Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(new SourceToParse("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); assertEquals(Collections.emptyList(), Arrays.asList(document.rootDoc().getFields(TypeFieldMapper.NAME))); } } diff --git a/server/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java b/server/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java index 747d951d5a8..6f38822092a 100644 --- a/server/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java +++ b/server/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java @@ -197,7 +197,7 @@ public class RecoveryDuringReplicationTests extends ESIndexLevelReplicationTestC 1, randomNonNegativeLong(), false, - SourceToParse.source("index", "type", "replica", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse("index", "type", "replica", new BytesArray("{}"), XContentType.JSON)); shards.promoteReplicaToPrimary(promotedReplica).get(); oldPrimary.close("demoted", randomBoolean()); oldPrimary.store().close(); @@ -210,7 +210,7 @@ public class RecoveryDuringReplicationTests extends ESIndexLevelReplicationTestC promotedReplica.applyIndexOperationOnPrimary( Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("index", "type", "primary", new BytesArray("{}"), XContentType.JSON), + new SourceToParse("index", "type", "primary", new BytesArray("{}"), XContentType.JSON), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, randomNonNegativeLong(), false); } diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java index 0ca449b3ca7..475caf06e30 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -357,7 +357,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { .setSource("{}", XContentType.JSON).setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get(); assertFalse(shard.shouldPeriodicallyFlush()); shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("test", "test", "1", new BytesArray("{}"), XContentType.JSON), + new SourceToParse("test", "test", "1", new BytesArray("{}"), XContentType.JSON), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false); assertTrue(shard.shouldPeriodicallyFlush()); final Translog translog = getTranslog(shard); @@ -407,7 +407,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { for (int i = 0; i < numberOfDocuments; i++) { assertThat(translog.currentFileGeneration(), equalTo(generation + rolls)); final Engine.IndexResult result = shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("test", "test", "1", new BytesArray("{}"), XContentType.JSON), + new SourceToParse("test", "test", "1", new BytesArray("{}"), XContentType.JSON), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false); final Translog.Location location = result.getTranslogLocation(); shard.afterWriteOperation(); diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index 7679595a7fa..4745904a554 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -1790,15 +1790,15 @@ public class IndexShardTests extends IndexShardTestCase { shard.applyDeleteOperationOnReplica(1, 2, "_doc", "id"); shard.getEngine().rollTranslogGeneration(); // isolate the delete in it's own generation shard.applyIndexOperationOnReplica(0, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(shard.shardId().getIndexName(), "_doc", "id", new BytesArray("{}"), XContentType.JSON)); shard.applyIndexOperationOnReplica(3, 3, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-3", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(shard.shardId().getIndexName(), "_doc", "id-3", new BytesArray("{}"), XContentType.JSON)); // Flushing a new commit with local checkpoint=1 allows to skip the translog gen #1 in recovery. shard.flush(new FlushRequest().force(true).waitIfOngoing(true)); shard.applyIndexOperationOnReplica(2, 3, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-2", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(shard.shardId().getIndexName(), "_doc", "id-2", new BytesArray("{}"), XContentType.JSON)); shard.applyIndexOperationOnReplica(5, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-5", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(shard.shardId().getIndexName(), "_doc", "id-5", new BytesArray("{}"), XContentType.JSON)); final int translogOps; if (randomBoolean()) { @@ -1912,7 +1912,7 @@ public class IndexShardTests extends IndexShardTestCase { // start a replica shard and index the second doc final IndexShard otherShard = newStartedShard(false); updateMappings(otherShard, shard.indexSettings().getIndexMetaData()); - SourceToParse sourceToParse = SourceToParse.source(shard.shardId().getIndexName(), "_doc", "1", + SourceToParse sourceToParse = new SourceToParse(shard.shardId().getIndexName(), "_doc", "1", new BytesArray("{}"), XContentType.JSON); otherShard.applyIndexOperationOnReplica(1, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); @@ -2033,11 +2033,11 @@ public class IndexShardTests extends IndexShardTestCase { final String indexName = shard.shardId().getIndexName(); // Index #0, index #1 shard.applyIndexOperationOnReplica(0, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "_doc", "doc-0", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "_doc", "doc-0", new BytesArray("{}"), XContentType.JSON)); flushShard(shard); shard.updateGlobalCheckpointOnReplica(0, "test"); // stick the global checkpoint here. shard.applyIndexOperationOnReplica(1, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "_doc", "doc-1", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "_doc", "doc-1", new BytesArray("{}"), XContentType.JSON)); flushShard(shard); assertThat(getShardDocUIDs(shard), containsInAnyOrder("doc-0", "doc-1")); // Here we try to increase term (i.e. a new primary is promoted) without rolling back a replica so we can keep stale operations @@ -2047,7 +2047,7 @@ public class IndexShardTests extends IndexShardTestCase { shard.getEngine().rollTranslogGeneration(); shard.markSeqNoAsNoop(1, "test"); shard.applyIndexOperationOnReplica(2, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "_doc", "doc-2", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "_doc", "doc-2", new BytesArray("{}"), XContentType.JSON)); flushShard(shard); assertThat(getShardDocUIDs(shard), containsInAnyOrder("doc-0", "doc-1", "doc-2")); closeShard(shard, false); @@ -3037,7 +3037,7 @@ public class IndexShardTests extends IndexShardTestCase { for (int i = offset + 1; i < operations; i++) { if (!rarely() || i == operations - 1) { // last operation can't be a gap as it's not a gap anymore final String id = Integer.toString(i); - SourceToParse sourceToParse = SourceToParse.source(indexShard.shardId().getIndexName(), "_doc", id, + SourceToParse sourceToParse = new SourceToParse(indexShard.shardId().getIndexName(), "_doc", id, new BytesArray("{}"), XContentType.JSON); indexShard.applyIndexOperationOnReplica(i, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); diff --git a/server/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java b/server/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java index 282404de9a4..d074ef33758 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java @@ -80,7 +80,7 @@ public class PrimaryReplicaSyncerTests extends IndexShardTestCase { for (int i = 0; i < numDocs; i++) { // Index doc but not advance local checkpoint. shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source(shard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON), + new SourceToParse(shard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, randomBoolean() ? IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP : randomNonNegativeLong(), true); } @@ -150,7 +150,7 @@ public class PrimaryReplicaSyncerTests extends IndexShardTestCase { for (int i = 0; i < numDocs; i++) { // Index doc but not advance local checkpoint. shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source(shard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON), + new SourceToParse(shard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false); } diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryTests.java index 694032bd988..48061b11d58 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryTests.java @@ -132,19 +132,19 @@ public class RecoveryTests extends ESIndexLevelReplicationTestCase { getTranslog(orgReplica).rollGeneration(); // isolate the delete in it's own generation // index #0 orgReplica.applyIndexOperationOnReplica(0, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "type", "id", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id", new BytesArray("{}"), XContentType.JSON)); // index #3 orgReplica.applyIndexOperationOnReplica(3, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "type", "id-3", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id-3", new BytesArray("{}"), XContentType.JSON)); // Flushing a new commit with local checkpoint=1 allows to delete the translog gen #1. orgReplica.flush(new FlushRequest().force(true).waitIfOngoing(true)); // index #2 orgReplica.applyIndexOperationOnReplica(2, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "type", "id-2", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id-2", new BytesArray("{}"), XContentType.JSON)); orgReplica.updateGlobalCheckpointOnReplica(3L, "test"); // index #5 -> force NoOp #4. orgReplica.applyIndexOperationOnReplica(5, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON)); final int translogOps; if (randomBoolean()) { @@ -196,19 +196,19 @@ public class RecoveryTests extends ESIndexLevelReplicationTestCase { orgReplica.flush(new FlushRequest().force(true)); // isolate delete#1 in its own translog generation and lucene segment // index #0 orgReplica.applyIndexOperationOnReplica(0, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "type", "id", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id", new BytesArray("{}"), XContentType.JSON)); // index #3 orgReplica.applyIndexOperationOnReplica(3, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "type", "id-3", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id-3", new BytesArray("{}"), XContentType.JSON)); // Flushing a new commit with local checkpoint=1 allows to delete the translog gen #1. orgReplica.flush(new FlushRequest().force(true).waitIfOngoing(true)); // index #2 orgReplica.applyIndexOperationOnReplica(2, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "type", "id-2", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id-2", new BytesArray("{}"), XContentType.JSON)); orgReplica.updateGlobalCheckpointOnReplica(3L, "test"); // index #5 -> force NoOp #4. orgReplica.applyIndexOperationOnReplica(5, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON)); if (randomBoolean()) { if (randomBoolean()) { @@ -312,7 +312,7 @@ public class RecoveryTests extends ESIndexLevelReplicationTestCase { long globalCheckpoint = 0; for (int i = 0; i < numDocs; i++) { Engine.IndexResult result = primaryShard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source(primaryShard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), + new SourceToParse(primaryShard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false); assertThat(result.getResultType(), equalTo(Engine.Result.Type.SUCCESS)); diff --git a/server/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java b/server/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java index 62db66eacda..812735092ba 100644 --- a/server/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java +++ b/server/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java @@ -77,7 +77,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -116,7 +116,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -150,7 +150,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -184,7 +184,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -231,7 +231,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { .endObject(); Exception e = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON))); + () -> defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON))); assertEquals("contexts must be a string, number or boolean or a list of string, number or boolean, but was [VALUE_NULL]", e.getCause().getMessage()); } @@ -252,7 +252,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startObject("completion") @@ -284,7 +284,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startObject("completion") @@ -327,7 +327,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { .endObject(); Exception e = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON))); + () -> defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON))); assertEquals("context array must have string, number or boolean values, but was [VALUE_NULL]", e.getCause().getMessage()); } @@ -364,7 +364,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { .endObject() .endArray() .endObject(); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder), + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON)); IndexableField[] fields = parsedDocument.rootDoc().getFields(fieldMapper.name()); assertContextSuggestFields(fields, 3); diff --git a/server/src/test/java/org/elasticsearch/search/suggest/completion/GeoContextMappingTests.java b/server/src/test/java/org/elasticsearch/search/suggest/completion/GeoContextMappingTests.java index a745384eb3e..85e97d16e3b 100644 --- a/server/src/test/java/org/elasticsearch/search/suggest/completion/GeoContextMappingTests.java +++ b/server/src/test/java/org/elasticsearch/search/suggest/completion/GeoContextMappingTests.java @@ -63,7 +63,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(jsonBuilder() .startObject() .startArray("completion") @@ -102,7 +102,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(jsonBuilder() .startObject() .startArray("completion") @@ -138,7 +138,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(jsonBuilder() .startObject() .startObject("completion") @@ -195,7 +195,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { .endObject() .endArray() .endObject(); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); diff --git a/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java index 711bbc1336c..f07c5e1b21f 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java @@ -332,7 +332,7 @@ public abstract class EngineTestCase extends ESTestCase { source.endObject(); } source.endObject(); - return nestedMapper.parse(SourceToParse.source("test", "type", docId, BytesReference.bytes(source), XContentType.JSON)); + return nestedMapper.parse(new SourceToParse("test", "type", docId, BytesReference.bytes(source), XContentType.JSON)); }; } diff --git a/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java b/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java index 830fcec3726..7090419e9f2 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java +++ b/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java @@ -31,6 +31,7 @@ import org.elasticsearch.index.mapper.DocumentMapperForType; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.Mapping; import org.elasticsearch.index.mapper.RootObjectMapper; +import org.elasticsearch.index.mapper.SourceToParse; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.similarity.SimilarityService; @@ -45,7 +46,6 @@ import java.util.concurrent.atomic.AtomicLong; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; -import static org.elasticsearch.index.mapper.SourceToParse.source; public class TranslogHandler implements Engine.TranslogRecoveryRunner { @@ -122,9 +122,8 @@ public class TranslogHandler implements Engine.TranslogRecoveryRunner { final String indexName = mapperService.index().getName(); final Engine.Index engineIndex = IndexShard.prepareIndex(docMapper(index.type()), mapperService.getIndexSettings().getIndexVersionCreated(), - source(indexName, index.type(), index.id(), index.source(), - XContentHelper.xContentType(index.source())) - .routing(index.routing()), index.seqNo(), index.primaryTerm(), + new SourceToParse(indexName, index.type(), index.id(), index.source(), XContentHelper.xContentType(index.source()), + index.routing()), index.seqNo(), index.primaryTerm(), index.version(), null, origin, index.getAutoGeneratedIdTimestamp(), true, SequenceNumbers.UNASSIGNED_SEQ_NO, 0); return engineIndex; case DELETE: diff --git a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java index 0a007f2a18e..84e88b6accc 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java @@ -697,8 +697,8 @@ public abstract class IndexShardTestCase extends ESTestCase { protected Engine.IndexResult indexDoc(IndexShard shard, String type, String id, String source, XContentType xContentType, String routing) throws IOException { - SourceToParse sourceToParse = SourceToParse.source(shard.shardId().getIndexName(), type, id, new BytesArray(source), xContentType); - sourceToParse.routing(routing); + SourceToParse sourceToParse = new SourceToParse( + shard.shardId().getIndexName(), type, id, new BytesArray(source), xContentType, routing); Engine.IndexResult result; if (shard.routingEntry().primary()) { result = shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, sourceToParse, diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowEngineIndexShardTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowEngineIndexShardTests.java index 9428ca89785..8d3c0c3b472 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowEngineIndexShardTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowEngineIndexShardTests.java @@ -39,13 +39,13 @@ public class FollowEngineIndexShardTests extends IndexShardTestCase { long seqNo = -1; for (int i = 0; i < 8; i++) { final String id = Long.toString(i); - SourceToParse sourceToParse = SourceToParse.source(indexShard.shardId().getIndexName(), "_doc", id, + SourceToParse sourceToParse = new SourceToParse(indexShard.shardId().getIndexName(), "_doc", id, new BytesArray("{}"), XContentType.JSON); indexShard.applyIndexOperationOnReplica(++seqNo, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); } long seqNoBeforeGap = seqNo; seqNo += 8; - SourceToParse sourceToParse = SourceToParse.source(indexShard.shardId().getIndexName(), "_doc", "9", + SourceToParse sourceToParse = new SourceToParse(indexShard.shardId().getIndexName(), "_doc", "9", new BytesArray("{}"), XContentType.JSON); indexShard.applyIndexOperationOnReplica(seqNo, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotShardTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotShardTests.java index f1de51c95b6..28244b523e1 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotShardTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotShardTests.java @@ -46,6 +46,7 @@ import org.elasticsearch.index.engine.InternalEngineFactory; import org.elasticsearch.index.fieldvisitor.FieldsVisitor; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.SeqNoFieldMapper; +import org.elasticsearch.index.mapper.SourceToParse; import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.seqno.SeqNoStats; import org.elasticsearch.index.seqno.SequenceNumbers; @@ -67,8 +68,6 @@ import java.util.Arrays; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; -import static org.elasticsearch.index.mapper.SourceToParse.source; - public class SourceOnlySnapshotShardTests extends IndexShardTestCase { public void testSourceIncomplete() throws IOException { @@ -293,9 +292,9 @@ public class SourceOnlySnapshotShardTests extends IndexShardTestCase { Uid uid = rootFieldsVisitor.uid(); BytesReference source = rootFieldsVisitor.source(); assert source != null : "_source is null but should have been filtered out at snapshot time"; - Engine.Result result = targetShard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, source - (index, uid.type(), uid.id(), source, XContentHelper.xContentType(source)) - .routing(rootFieldsVisitor.routing()), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, 1, false); + Engine.Result result = targetShard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, + new SourceToParse(index, uid.type(), uid.id(), source, XContentHelper.xContentType(source), + rootFieldsVisitor.routing()), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, 1, false); if (result.getResultType() != Engine.Result.Type.SUCCESS) { throw new IllegalStateException("failed applying post restore operation result: " + result .getResultType(), result.getFailure());