From dc028937ba76645aa242af250816e65b388089cc Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Sun, 23 Dec 2018 16:25:48 -0500 Subject: [PATCH 1/2] Make SourceToParse immutable 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 a ctor of SourceToParse. --- .../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 | 44 +++--- .../percolator/PercolateQueryBuilder.java | 2 +- .../PercolatorFieldMapperTests.java | 32 ++--- .../ICUCollationKeywordFieldMapperTests.java | 22 +-- .../AnnotatedTextFieldMapperTests.java | 18 +-- .../murmur3/Murmur3FieldMapperTests.java | 3 +- .../index/mapper/size/SizeMappingTests.java | 6 +- .../action/bulk/TransportShardBulkAction.java | 10 +- .../index/mapper/DocumentMapper.java | 4 +- .../index/mapper/SourceToParse.java | 16 +-- .../elasticsearch/index/shard/IndexShard.java | 7 +- .../index/termvectors/TermVectorsService.java | 10 +- .../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 | 26 ++-- .../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 | 6 +- .../indices/recovery/RecoveryTests.java | 18 +-- .../CategoryContextMappingTests.java | 18 +-- .../completion/GeoContextMappingTests.java | 8 +- .../index/engine/EngineTestCase.java | 2 +- .../index/engine/TranslogHandler.java | 5 +- .../index/shard/IndexShardTestCase.java | 4 +- .../engine/FollowEngineIndexShardTests.java | 4 +- .../SourceOnlySnapshotShardTests.java | 6 +- 66 files changed, 433 insertions(+), 436 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 5b120a8eba732..7ebe29e857934 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 @@ private static Response prepareRamIndex(Request request, String type = indexService.mapperService().documentMapper().type(); BytesReference document = request.contextSetup.document; XContentType xContentType = request.contextSetup.xContentType; - SourceToParse sourceToParse = SourceToParse.source(index, type, "_id", document, xContentType); + SourceToParse sourceToParse = SourceToParse.source(index, type, "_id", null, document, xContentType); ParsedDocument parsedDocument = indexService.mapperService().documentMapper().parse(sourceToParse); indexWriter.addDocuments(parsedDocument.docs()); try (IndexReader indexReader = DirectoryReader.open(indexWriter)) { diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/DenseVectorFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/DenseVectorFieldMapperTests.java index db0bf5d48d444..dc81f6fd5c6b5 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/DenseVectorFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/DenseVectorFieldMapperTests.java @@ -58,7 +58,7 @@ public void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); float[] expectedArray = {-12.1f, 100.7f, -4}; - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference + ParsedDocument doc1 = mapper.parse(SourceToParse.source("test-index", "_doc", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startArray("my-dense-vector").value(expectedArray[0]).value(expectedArray[1]).value(expectedArray[2]).endArray() diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureFieldMapperTests.java index 8e400815bec77..e8ecf7143871e 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureFieldMapperTests.java @@ -72,7 +72,7 @@ public void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 10) @@ -84,7 +84,7 @@ public void testDefaults() throws Exception { assertThat(fields[0], Matchers.instanceOf(FeatureField.class)); FeatureField featureField1 = (FeatureField) fields[0]; - ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 12) @@ -108,7 +108,7 @@ public void testNegativeScoreImpact() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 10) @@ -120,7 +120,7 @@ public void testNegativeScoreImpact() throws Exception { assertThat(fields[0], Matchers.instanceOf(FeatureField.class)); FeatureField featureField1 = (FeatureField) fields[0]; - ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 12) @@ -145,7 +145,7 @@ public void testRejectMultiValuedFields() throws MapperParsingException, IOExcep assertEquals(mapping, mapper.mappingSource().toString()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", Arrays.asList(10, 20)) @@ -155,7 +155,7 @@ public void testRejectMultiValuedFields() throws MapperParsingException, IOExcep e.getCause().getMessage()); e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 fccb62b1a3439..8abfefe91888a 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") @@ -95,7 +95,7 @@ public void testRejectMultiValuedFields() throws MapperParsingException, IOExcep assertEquals(mapping, mapper.mappingSource().toString()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") @@ -107,7 +107,7 @@ public void testRejectMultiValuedFields() throws MapperParsingException, IOExcep "START_ARRAY", e.getCause().getMessage()); e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 67e0fad53ec49..dc3c5c49eb3dc 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -115,7 +115,7 @@ public void testNotIndexed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -139,7 +139,7 @@ public void testNoDocValues() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -163,7 +163,7 @@ public void testStore() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -192,7 +192,7 @@ public void testCoerce() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -216,7 +216,7 @@ public void testCoerce() throws Exception { assertEquals(mapping, mapper2.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -245,7 +245,7 @@ private void doTestIgnoreMalformed(String value, String exceptionMessageContains assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", value) @@ -261,7 +261,7 @@ private void doTestIgnoreMalformed(String value, String exceptionMessageContains DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", value) @@ -286,7 +286,7 @@ public void testNullValue() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -308,7 +308,7 @@ public void testNullValue() throws IOException { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 e805cf81bdf8c..b9e3f921cfa5d 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 @@ protected Collection> getPlugins() { 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(SourceToParse.source("test-index", "_doc", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -103,7 +103,7 @@ public void testDefaults() throws Exception { 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(SourceToParse.source("test-index", "_doc", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -118,7 +118,7 @@ public void testErrors() { // 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(SourceToParse.source("test-index", "_doc", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -133,7 +133,7 @@ public void testErrors() { // 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(SourceToParse.source("test-index", "_doc", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -148,7 +148,7 @@ public void testErrors() { // 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(SourceToParse.source("test-index", "_doc", "1", null, 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 34ad1934a3e09..bb82946bf081a 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 @@ private SourceToParse createDocument(String fieldValue) throws Exception { .field("test", fieldValue) .endObject()); - return SourceToParse.source("test", "person", "1", request, XContentType.JSON); + return SourceToParse.source("test", "person", "1", null, 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 97ca8900ea0e0..cc19f602d1aca 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 @@ -64,12 +64,12 @@ public void testSingleLevel() throws Exception { // Doc without join ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)); + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)); assertNull(doc.rootDoc().getBinaryValue("join_field")); // Doc parent doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "parent") .endObject()), XContentType.JSON)); assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); @@ -77,19 +77,19 @@ public void testSingleLevel() throws Exception { // Doc child doc = docMapper.parse(SourceToParse.source("test", "type", "2", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", "1") .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON)); 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", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "unknown") .endObject()), XContentType.JSON))); assertThat(exc.getRootCause().getMessage(), containsString("unknown join name [unknown] for field [join_field]")); @@ -110,21 +110,21 @@ public void testParentIdSpecifiedAsNumber() throws Exception { DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "2", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", 1) .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON)); 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", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + doc = docMapper.parse(SourceToParse.source("test", "type", "2", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", 1.0) .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON)); assertEquals("1.0", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); } @@ -148,12 +148,12 @@ public void testMultipleLevels() throws Exception { // Doc without join ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)); + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)); assertNull(doc.rootDoc().getBinaryValue("join_field")); // Doc parent doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("join_field", "parent") .endObject()), XContentType.JSON)); @@ -161,13 +161,13 @@ public void testMultipleLevels() throws Exception { assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); // Doc child - doc = docMapper.parse(SourceToParse.source("test", "type", "2", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + doc = docMapper.parse(SourceToParse.source("test", "type", "2", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", "1") .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON)); 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()); @@ -175,15 +175,15 @@ public void testMultipleLevels() throws Exception { // Doc child missing parent MapperException exc = expectThrows(MapperParsingException.class, () -> docMapper.parse(SourceToParse.source("test", "type", "2", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "child") - .endObject()), XContentType.JSON).routing("1"))); + .endObject()), XContentType.JSON))); 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", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", "1") @@ -192,20 +192,20 @@ public void testMultipleLevels() throws Exception { assertThat(exc.getRootCause().getMessage(), containsString("[routing] is missing for join field [join_field]")); // Doc grand_child - doc = docMapper.parse(SourceToParse.source("test", "type", "3", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + doc = docMapper.parse(SourceToParse.source("test", "type", "3", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "grand_child") .field("parent", "2") .endObject() - .endObject()), XContentType.JSON).routing("1")); + .endObject()), XContentType.JSON)); 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", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "unknown") .endObject()), XContentType.JSON))); assertThat(exc.getRootCause().getMessage(), containsString("unknown join name [unknown] for field [join_field]")); 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 3c0076ea18f9e..78324ab7aef42 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java @@ -585,7 +585,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException { } docMapper = mapperService.documentMapper(type); for (BytesReference document : documents) { - docs.add(docMapper.parse(source(context.index().getName(), type, "_temp_id", document, documentXContentType))); + docs.add(docMapper.parse(source(context.index().getName(), type, "_temp_id", null, document, documentXContentType))); } FieldNameAnalyzer fieldNameAnalyzer = (FieldNameAnalyzer) docMapper.mappers().indexAnalyzer(); diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java index 80524a2f862fe..8df004ac68adb 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java @@ -480,7 +480,7 @@ public void testPercolatorFieldMapper() throws Exception { addQueryFieldMappings(); QueryBuilder queryBuilder = termQuery("field", "value"); ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - BytesReference.bytes(XContentFactory + null, BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .field(fieldName, queryBuilder) @@ -498,7 +498,7 @@ public void testPercolatorFieldMapper() throws Exception { // add an query for which we don't extract terms from queryBuilder = rangeQuery("field").from("a").to("z"); - doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", BytesReference.bytes(XContentFactory + doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", null, BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .field(fieldName, queryBuilder) @@ -525,7 +525,7 @@ public void testStoringQueries() throws Exception { for (QueryBuilder query : queries) { ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, query) .endObject()), XContentType.JSON)); @@ -539,7 +539,7 @@ public void testQueryWithRewrite() throws Exception { client().prepareIndex("remote", "doc", "1").setSource("field", "value").get(); QueryBuilder queryBuilder = termsLookupQuery("field", new TermsLookup("remote", "doc", "1", "field")); ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - BytesReference.bytes(XContentFactory + null, BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .field(fieldName, queryBuilder) @@ -559,7 +559,7 @@ public void testQueryWithRewrite() throws Exception { public void testPercolatorFieldMapperUnMappedField() throws Exception { addQueryFieldMappings(); MapperParsingException exception = expectThrows(MapperParsingException.class, () -> { - mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", BytesReference.bytes(XContentFactory + mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", null, BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .field(fieldName, termQuery("unmapped_field", "value")) @@ -573,7 +573,7 @@ public void testPercolatorFieldMapperUnMappedField() throws Exception { 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(SourceToParse.source("test", "doc", "1", null, BytesReference .bytes(XContentFactory .jsonBuilder() .startObject() @@ -582,7 +582,7 @@ public void testPercolatorFieldMapper_noQuery() throws Exception { 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(SourceToParse.source("test", "doc", "1", null, BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .nullField(fieldName) @@ -620,7 +620,7 @@ public void testMultiplePercolatorFields() throws Exception { QueryBuilder queryBuilder = matchQuery("field", "value"); ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", - BytesReference.bytes(jsonBuilder().startObject() + null, BytesReference.bytes(jsonBuilder().startObject() .field("query_field1", queryBuilder) .field("query_field2", queryBuilder) .endObject()), @@ -651,7 +651,7 @@ public void testNestedPercolatorField() throws Exception { QueryBuilder queryBuilder = matchQuery("field", "value"); ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", - BytesReference.bytes(jsonBuilder().startObject().startObject("object_field") + null, BytesReference.bytes(jsonBuilder().startObject().startObject("object_field") .field("query_field", queryBuilder) .endObject().endObject()), XContentType.JSON)); @@ -660,7 +660,7 @@ public void testNestedPercolatorField() throws Exception { assertQueryBuilder(queryBuilderAsBytes, queryBuilder); doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", - BytesReference.bytes(jsonBuilder().startObject() + null, BytesReference.bytes(jsonBuilder().startObject() .startArray("object_field") .startObject().field("query_field", queryBuilder).endObject() .endArray() @@ -672,7 +672,7 @@ public void testNestedPercolatorField() throws Exception { MapperParsingException e = expectThrows(MapperParsingException.class, () -> { mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", - BytesReference.bytes(jsonBuilder().startObject() + null, BytesReference.bytes(jsonBuilder().startObject() .startArray("object_field") .startObject().field("query_field", queryBuilder).endObject() .startObject().field("query_field", queryBuilder).endObject() @@ -757,7 +757,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { query.endObject(); ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType()) .endObject()), XContentType.JSON)); @@ -795,7 +795,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { query.endObject(); doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType()) .endObject()), XContentType.JSON)); @@ -881,7 +881,7 @@ public void testDuplicatedClauses() throws Exception { .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", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), XContentType.JSON)); @@ -903,7 +903,7 @@ public void testDuplicatedClauses() throws Exception { .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", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), XContentType.JSON)); @@ -928,7 +928,7 @@ public void testDuplicatedClauses() throws Exception { .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", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), XContentType.JSON)); 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 f39ae886dc45b..c8e386b4b2ca7 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -112,7 +112,7 @@ public void testNullValue() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -129,7 +129,7 @@ public void testNullValue() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .endObject()), @@ -138,7 +138,7 @@ public void testNullValue() throws IOException { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -164,7 +164,7 @@ public void testEnableStore() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -186,7 +186,7 @@ public void testDisableIndex() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -209,7 +209,7 @@ public void testDisableDocValues() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -230,7 +230,7 @@ public void testMultipleValues() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", Arrays.asList("1234", "5678")) @@ -293,7 +293,7 @@ public void testIndexOptions() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -326,7 +326,7 @@ public void testEnableNorms() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -350,7 +350,7 @@ public void testCollator() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 4156fd206722d..b730f9575eeca 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 void testAnnotationInjection() throws IOException { // 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 = SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", annotatedText) @@ -171,7 +171,7 @@ public void testToleranceForBadAnnotationMarkup() throws IOException { new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); String annotatedText = "foo [bar](MissingEndBracket baz"; - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", annotatedText) @@ -260,7 +260,7 @@ public void testDefaults() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -292,7 +292,7 @@ public void testEnableStore() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -316,7 +316,7 @@ public void testDisableNorms() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -347,7 +347,7 @@ public void testIndexOptions() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(jsonDoc.endObject()), XContentType.JSON)); for (Map.Entry entry : supportedOptions.entrySet()) { @@ -369,7 +369,7 @@ public void testDefaultPositionIncrementGap() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[] {"a", "b"}) @@ -411,7 +411,7 @@ public void testPositionIncrementGap() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[]{"a", "b"}) @@ -570,7 +570,7 @@ public void testTermVectors() throws IOException { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 1df613ab3f9b3..e1400d252b5ac 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,8 @@ public void testDefaults() throws Exception { .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(SourceToParse.source("test", "type", "1", null, + 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 dc14373026430..52c3429e476ee 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 void testSizeEnabled() throws Exception { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, source, XContentType.JSON)); boolean stored = false; boolean points = false; @@ -78,7 +78,7 @@ public void testSizeDisabled() throws Exception { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, source, XContentType.JSON)); assertThat(doc.rootDoc().getField("_size"), nullValue()); } @@ -92,7 +92,7 @@ public void testSizeNotSet() throws Exception { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, 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 e04da71749f09..f518eaf9b8282 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -421,9 +421,8 @@ private static Engine.Result performOpOnReplica(DocWriteResponse primaryResponse final IndexRequest indexRequest = (IndexRequest) docWriteRequest; final ShardId shardId = replica.shardId(); final SourceToParse sourceToParse = - SourceToParse.source(shardId.getIndexName(), - indexRequest.type(), indexRequest.id(), indexRequest.source(), indexRequest.getContentType()) - .routing(indexRequest.routing()); + SourceToParse.source(shardId.getIndexName(), indexRequest.type(), indexRequest.id(), indexRequest.routing(), + indexRequest.source(), indexRequest.getContentType()); result = replica.applyIndexOperationOnReplica(primaryResponse.getSeqNo(), primaryResponse.getVersion(), indexRequest.getAutoGeneratedTimestamp(), indexRequest.isRetry(), sourceToParse); break; @@ -456,9 +455,8 @@ private static void executeIndexRequestOnPrimary(BulkPrimaryExecutionContext con MappingUpdatePerformer mappingUpdater) throws Exception { final IndexRequest request = context.getRequestToExecute(); final IndexShard primary = context.getPrimary(); - final SourceToParse sourceToParse = - SourceToParse.source(request.index(), request.type(), request.id(), request.source(), request.getContentType()) - .routing(request.routing()); + final SourceToParse sourceToParse = SourceToParse.source(request.index(), request.type(), request.id(), request.routing(), + request.source(), request.getContentType()); executeOnPrimaryWhileHandlingMappingUpdates(context, () -> 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 cb962609fb436..413717d6b08f2 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 ParsedDocument parse(SourceToParse source) throws MapperParsingException } 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 = SourceToParse.source(index, type, id, null, 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 = SourceToParse.source(index, type, id, null, 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 0130207c0a78e..446d117a1d403 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java @@ -27,9 +27,9 @@ public class SourceToParse { - public static SourceToParse source(String index, String type, String id, BytesReference source, + public static SourceToParse source(String index, String type, String id, String routing, BytesReference source, XContentType contentType) { - return new SourceToParse(index, type, id, source, contentType); + return new SourceToParse(index, type, id, routing, source, contentType); } private final BytesReference source; @@ -40,14 +40,15 @@ public static SourceToParse source(String index, String type, String id, BytesRe private final String id; - private String routing; + private final 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, String routing, BytesReference source, XContentType xContentType) { this.index = Objects.requireNonNull(index); this.type = Objects.requireNonNull(type); this.id = Objects.requireNonNull(id); + this.routing = routing; // we always convert back to byte array, since we store it and Field only supports bytes.. // 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()); @@ -78,11 +79,6 @@ public XContentType getXContentType() { 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 37c7ace855cf2..0d6bd8dc853e6 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -716,8 +716,7 @@ private Engine.IndexResult applyIndexOperation(Engine engine, long seqNo, long o sourceWithResolvedType = sourceToParse; } else { sourceWithResolvedType = SourceToParse.source(sourceToParse.index(), resolvedType, sourceToParse.id(), - sourceToParse.source(), sourceToParse.getXContentType()); - sourceWithResolvedType.routing(sourceToParse.routing()); + sourceToParse.routing(), sourceToParse.source(), sourceToParse.getXContentType()); } operation = prepareIndex(docMapper(resolvedType), indexSettings.getIndexVersionCreated(), sourceWithResolvedType, seqNo, opPrimaryTerm, version, versionType, origin, autoGeneratedTimeStamp, isRetry, ifSeqNo, ifPrimaryTerm); @@ -1300,8 +1299,8 @@ private Engine.Result applyTranslogOperation(Engine engine, Translog.Operation o // 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())); + source(shardId.getIndexName(), index.type(), index.id(), index.routing(), index.source(), + XContentHelper.xContentType(index.source()))); 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 68f175f7ed6ae..d03c2c9257bd3 100644 --- a/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java +++ b/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java @@ -302,8 +302,8 @@ private static Fields generateTermVectors(IndexShard indexShard, 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.routing(), + request.doc(), request.xContentType()); // select the right fields and generate term vectors ParseContext.Document doc = parsedDocument.rootDoc(); @@ -331,11 +331,11 @@ private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVect request.offsets(), request.perFieldAnalyzer(), seenFields); } - private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc, - XContentType xContentType) { + private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, String routing, + BytesReference doc, XContentType xContentType) { 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(source(index, type, "_id_for_tv_api", null, doc, xContentType)); 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 3b29d15bf3fb2..f140f4e8d915c 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 void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - ParsedDocument d = mapper.parse(SourceToParse.source("test", "test", "1", BytesReference.bytes(doc), XContentType.JSON)); + ParsedDocument d = mapper.parse(SourceToParse.source("test", "test", "1", null, 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(SourceToParse.source("test", "test", "2", null, 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(SourceToParse.source("test", "test", "3", null, BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); // test remove duplicate value @@ -88,7 +88,7 @@ public void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - d = mapper.parse(SourceToParse.source("test", "test", "4", BytesReference.bytes(doc), XContentType.JSON)); + d = mapper.parse(SourceToParse.source("test", "test", "4", null, 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 5f4cd98600b46..fc0bfc5a03065 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java @@ -92,7 +92,7 @@ public void testStoredValue() throws IOException { for (byte[] value : Arrays.asList(binaryValue1, binaryValue2)) { ParsedDocument doc = mapperService.documentMapper().parse(SourceToParse.source("test", "type", "id", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), XContentType.JSON)); BytesRef indexedValue = doc.rootDoc().getBinaryValue("field"); assertEquals(new BytesRef(value), indexedValue); 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 fd98a8199a22f..96658a2fb8c65 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 void testDefaults() throws IOException { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", true) @@ -141,7 +141,7 @@ public void testParsesBooleansStrict() throws IOException { .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(SourceToParse.source("test", "type", "1", null, source, XContentType.JSON))); assertEquals("failed to parse field [field] of type [boolean]", ex.getMessage()); } @@ -164,7 +164,7 @@ public void testMultiFields() throws IOException { .startObject() .field("field", false) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, source, XContentType.JSON)); assertNotNull(doc.rootDoc().getField("field.as_string")); } @@ -187,7 +187,7 @@ public void testDocValues() throws Exception { DocumentMapper defaultMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); - ParsedDocument parsedDoc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument parsedDoc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 09394b396679f..671c4992b0ca3 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java @@ -36,7 +36,7 @@ public void testCamelCaseFieldNameStaysAsIs() throws Exception { DocumentMapper documentMapper = index.mapperService().documentMapper("type"); ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("thisIsCamelCase", "value1") .endObject()), XContentType.JSON)); 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 513ba039c955e..558f0f4eb3a77 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java @@ -167,7 +167,7 @@ public void testParsingMinimal() throws Exception { Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", "suggestion") .endObject()), @@ -188,7 +188,7 @@ public void testParsingFailure() throws Exception { MapperParsingException e = expectThrows(MapperParsingException.class, () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", 1.0) .endObject()), @@ -221,7 +221,7 @@ public void testKeywordWithSubCompletionAndContext() throws Exception { .parse("type1", new CompressedXContent(mapping)); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("keywordfield", "key1", "key2", "key3") .endObject()), @@ -276,7 +276,7 @@ public void testCompletionWithContextAndSubCompletion() throws Exception { .parse("type1", new CompressedXContent(mapping)); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("suggest") .array("input","timmy","starbucks") @@ -332,7 +332,7 @@ public void testCompletionWithContextAndSubCompletionIndexByPath() throws Except .parse("type1", new CompressedXContent(mapping)); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("suggest", "timmy","starbucks") .array("cat","cafe","food") @@ -369,7 +369,7 @@ public void testKeywordWithSubCompletionAndStringInsert() throws Exception { .parse("type1", new CompressedXContent(mapping)); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("geofield", "drm3btev3e86")//"41.12,-71.34" .endObject()), @@ -400,7 +400,7 @@ public void testCompletionTypeWithSubCompletionFieldAndStringInsert() throws Exc .parse("type1", new CompressedXContent(mapping)); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("suggest", "suggestion") .endObject()), @@ -432,7 +432,7 @@ public void testCompletionTypeWithSubCompletionFieldAndObjectInsert() throws Exc .parse("type1", new CompressedXContent(mapping)); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .array("input","New York", "NY") @@ -470,7 +470,7 @@ public void testCompletionTypeWithSubKeywordFieldAndObjectInsert() throws Except .parse("type1", new CompressedXContent(mapping)); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .array("input","New York", "NY") @@ -510,7 +510,7 @@ public void testCompletionTypeWithSubKeywordFieldAndStringInsert() throws Except .parse("type1", new CompressedXContent(mapping)); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", "suggestion") .endObject()), @@ -538,7 +538,7 @@ public void testParsingMultiValued() throws Exception { Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("completion", "suggestion1", "suggestion2") .endObject()), @@ -562,7 +562,7 @@ public void testParsingWithWeight() throws Exception { Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .field("input", "suggestion") @@ -588,7 +588,7 @@ public void testParsingMultiValueWithWeight() throws Exception { Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .array("input", "suggestion1", "suggestion2", "suggestion3") @@ -631,7 +631,7 @@ public void testParsingWithGeoFieldAlias() throws Exception { Mapper fieldMapper = mapperService.documentMapper().mappers().getMapper("completion"); ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .field("input", "suggestion") @@ -656,7 +656,7 @@ public void testParsingFull() throws Exception { Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("completion") .startObject() @@ -694,7 +694,7 @@ public void testParsingMixed() throws Exception { Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("completion") .startObject() @@ -734,7 +734,7 @@ public void testNonContextEnabledParsingWithContexts() throws Exception { .parse("type1", new CompressedXContent(mapping)); try { defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field1") .field("input", "suggestion1") @@ -765,7 +765,7 @@ public void testFieldValueValidation() throws Exception { charsRefBuilder.setCharAt(2, '\u001F'); try { defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) .endObject()), @@ -780,7 +780,7 @@ public void testFieldValueValidation() throws Exception { charsRefBuilder.setCharAt(2, '\u0000'); try { defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) .endObject()), @@ -795,7 +795,7 @@ public void testFieldValueValidation() throws Exception { charsRefBuilder.setCharAt(2, '\u001E'); try { defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) .endObject()), @@ -809,7 +809,7 @@ public void testFieldValueValidation() throws Exception { // empty inputs are ignored ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("completion", " ", "") .endObject()), @@ -822,7 +822,7 @@ public void testFieldValueValidation() throws Exception { // null inputs are ignored ParsedDocument nullDoc = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("completion") .endObject()), 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 7936b97fad4f2..251d7e5a9ba28 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 void testCopyToFieldsParsing() throws Exception { .field("int_to_str_test", 42) .endObject()); - ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)); + ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToFieldsInnerObjectParsing() throws Exception { .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(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToDynamicInnerObjectParsing() throws Exception { .field("new_field", "bar") .endObject()); - ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, + ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToDynamicInnerInnerObjectParsing() throws Exception { .field("new_field", "bar") .endObject()); - ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, + ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToStrictDynamicInnerObjectParsing() throws Exception { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToInnerStrictDynamicInnerObjectParsing() throws Exception { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(SourceToParse.source("test", "type1", "1", null, json, XContentType.JSON)).rootDoc(); fail(); } catch (MapperParsingException ex) { assertThat(ex.getMessage(), @@ -394,7 +394,7 @@ public void testCopyToNestedField() throws Exception { .endObject(); ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(jsonDoc), XContentType.JSON)); + null, BytesReference.bytes(jsonDoc), XContentType.JSON)); assertEquals(6, doc.docs().size()); Document nested = doc.docs().get(0); @@ -562,7 +562,7 @@ public void testCopyToDynamicNestedObjectParsing() throws Exception { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 023fa5ca051aa..3f9f5f1df3ee5 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-11") @@ -95,7 +95,7 @@ public void testNotIndexed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-11") @@ -117,7 +117,7 @@ public void testNoDocValues() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-11") @@ -139,7 +139,7 @@ public void testStore() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-11") @@ -166,7 +166,7 @@ public void testIgnoreMalformed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "2016-03-99") @@ -182,7 +182,7 @@ public void testIgnoreMalformed() throws Exception { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -204,7 +204,7 @@ public void testChangeFormat() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 1457654400) @@ -230,7 +230,7 @@ public void testFloatEpochFormat() throws IOException { long epochMillis = randomNonNegativeLong(); String epochFloatValue = epochMillis + "." + randomIntBetween(0, 999); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", epochFloatValue) @@ -252,7 +252,7 @@ public void testChangeLocale() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 1457654400) @@ -273,7 +273,7 @@ public void testNullValue() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -294,7 +294,7 @@ public void testNullValue() throws IOException { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -363,7 +363,7 @@ public void testTimeZoneParsing() throws Exception { 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(SourceToParse.source("test", "type", "1", null, 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 8cd39d72ad3a9..87871b63854e2 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java @@ -180,7 +180,7 @@ public void run() { ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "test", fieldName, - new BytesArray("{ \"" + fieldName + "\" : \"test\" }"), + null, new BytesArray("{ \"" + fieldName + "\" : \"test\" }"), XContentType.JSON)); Mapping update = doc.dynamicMappingsUpdate(); assert update != null; @@ -203,7 +203,7 @@ public void run() { ParsedDocument parsedDoc = documentMapper.parse(SourceToParse.source("test", "test", "random", - source, + null, source, XContentType.JSON)); if (parsedDoc.dynamicMappingsUpdate() != null) { // not in the mapping yet, try again 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 2ec49e5b20431..0737f92dc136d 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 void testFieldDisabled() throws Exception { .field("foo", "1234") .field("bar", 10) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertNull(doc.rootDoc().getField("foo")); assertNotNull(doc.rootDoc().getField("bar")); assertNotNull(doc.rootDoc().getField(IdFieldMapper.NAME)); @@ -98,7 +98,7 @@ public void testDotsWithExistingMapper() throws Exception { .field("baz", 789) .endObject() .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDotsWithExistingNestedMapper() throws Exception { .field("foo.bar", 123) .endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testUnexpectedFieldMappingType() throws Exception { 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(SourceToParse.source("test", "type", "1", null, 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(SourceToParse.source("test", "type", "2", null, 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(SourceToParse.source("test", "type", "2", null, bytes, XContentType.JSON))); assertThat(exception.getMessage(), containsString("failed to parse field [geo] of type [geo_shape]")); } @@ -178,7 +178,7 @@ public void testDotsWithDynamicNestedMapper() throws Exception { .field("foo.bar",42) .endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals( "It is forbidden to create dynamic nested objects ([foo]) through `copy_to` or dots in field names", e.getMessage()); @@ -226,7 +226,7 @@ public void testNestedHaveIdAndTypeFields() throws Exception { // 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", - BytesReference.bytes(doc), XContentType.JSON)); + null, BytesReference.bytes(doc), XContentType.JSON)); assertEquals(2, result.docs().size()); // Nested document: assertNotNull(result.docs().get(0).getField(IdFieldMapper.NAME)); @@ -258,7 +258,7 @@ public void testPropagateDynamicWithExistingMapper() throws Exception { .startObject().startObject("foo") .field("bar", "something") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertNotNull(doc.dynamicMappingsUpdate()); assertNotNull(doc.rootDoc().getField("foo.bar")); } @@ -278,7 +278,7 @@ public void testPropagateDynamicWithDynamicMapper() throws Exception { .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(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertNotNull(doc.dynamicMappingsUpdate()); assertNotNull(doc.rootDoc().getField("foo.bar.baz")); } @@ -297,7 +297,7 @@ public void testDynamicRootFallback() throws Exception { .startObject().startObject("foo") .field("bar", "something") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertNull(doc.dynamicMappingsUpdate()); assertNull(doc.rootDoc().getField("foo.bar")); } @@ -428,7 +428,7 @@ public void testDynamicGeoPointArrayWithTemplate() throws Exception { .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(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo").length); } @@ -446,7 +446,7 @@ public void testDynamicLongArrayWithTemplate() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -461,7 +461,7 @@ public void testDynamicLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -477,7 +477,7 @@ public void testDynamicFalseLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo").length); } @@ -494,7 +494,7 @@ public void testDynamicStrictLongArray() throws Exception { .value(1) .endArray().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -511,7 +511,7 @@ public void testMappedGeoPointArray() throws Exception { .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(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo").length); } @@ -527,7 +527,7 @@ public void testMappedLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -545,7 +545,7 @@ public void testDynamicObjectWithTemplate() throws Exception { .startObject().startObject("foo") .field("bar", "baz") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(2, doc.rootDoc().getFields("foo.bar").length); } @@ -560,7 +560,7 @@ public void testDynamicFalseObject() throws Exception { .startObject().startObject("foo") .field("bar", "baz") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo.bar").length); } @@ -576,7 +576,7 @@ public void testDynamicStrictObject() throws Exception { .field("bar", "baz") .endObject().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -591,7 +591,7 @@ public void testDynamicFalseValue() throws Exception { .startObject() .field("bar", "baz") .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("bar").length); } @@ -607,7 +607,7 @@ public void testDynamicStrictValue() throws Exception { .field("bar", "baz") .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); } @@ -622,7 +622,7 @@ public void testDynamicFalseNull() throws Exception { .startObject() .field("bar", (String) null) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("bar").length); } @@ -638,7 +638,7 @@ public void testDynamicStrictNull() throws Exception { .field("bar", (String) null) .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); } @@ -652,7 +652,7 @@ public void testMappedNullValue() throws Exception { 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(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo").length); } @@ -667,7 +667,7 @@ public void testDynamicDottedFieldNameLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongArrayWithParentTemplate() throws Excep .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongArrayWithExistingParent() throws Excep .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongArrayWithExistingParentWrongType() thr .value(1) .endArray().endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseDottedFieldNameLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length); } @@ -781,7 +781,7 @@ public void testDynamicStrictDottedFieldNameLongArray() throws Exception { .value(1) .endArray().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -794,7 +794,7 @@ public void testDynamicDottedFieldNameLong() throws Exception { 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(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongWithParentTemplate() throws Exception 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(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongWithExistingParent() throws Exception 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(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongWithExistingParentWrongType() throws E .startObject().field("foo.bar.baz", 0) .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseDottedFieldNameLong() throws Exception { 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(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length); } @@ -898,7 +898,7 @@ public void testDynamicStrictDottedFieldNameLong() throws Exception { .startObject().field("foo.bar.baz", 0) .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -912,7 +912,7 @@ public void testDynamicDottedFieldNameObject() throws Exception { .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(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameObjectWithParentTemplate() throws Exceptio .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(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameObjectWithExistingParent() throws Exceptio 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(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameObjectWithExistingParentWrongType() throws 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(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseDottedFieldNameObject() throws Exception { .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(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz.a").length); } @@ -1025,7 +1025,7 @@ public void testDynamicStrictDottedFieldNameObject() throws Exception { .field("a", 0) .endObject().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -1036,12 +1036,12 @@ public void testDocumentContainsMetadataField() throws Exception { 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(SourceToParse.source("test", "type", "1", null, 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(SourceToParse.source("test", "type", "1", null, bytes2, XContentType.JSON)); // parses without error } public void testSimpleMapper() throws Exception { @@ -1053,10 +1053,10 @@ public void testSimpleMapper() throws Exception { 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(SourceToParse.source("test", "person", "1", null, 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(SourceToParse.source("test", "person", "1", null, json, XContentType.JSON)).rootDoc(); } public void testParseToJsonAndParse() throws Exception { @@ -1067,7 +1067,7 @@ public void testParseToJsonAndParse() throws Exception { // 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(SourceToParse.source("test", "person", "1", null, 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 void testSimpleParser() throws Exception { 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(SourceToParse.source("test", "person", "1", null, 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 void testSimpleParserNoTypeNoId() throws Exception { 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(SourceToParse.source("test", "person", "1", null, 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 void testNoDocumentSent() throws Exception { BytesReference json = new BytesArray("".getBytes(StandardCharsets.UTF_8)); try { - docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(SourceToParse.source("test", "person", "1", null, 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 void testNoLevel() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("test1", "value1") @@ -1150,7 +1150,7 @@ public void testTypeLevel() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("test1", "value1") @@ -1170,7 +1170,7 @@ public void testNoLevelWithFieldTypeAsValue() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("type", "value_type") @@ -1192,7 +1192,7 @@ public void testTypeLevelWithFieldTypeAsValue() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("type", "value_type") @@ -1214,7 +1214,7 @@ public void testNoLevelWithFieldTypeAsObject() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("type").field("type_field", "type_value").endObject() @@ -1236,7 +1236,7 @@ public void testTypeLevelWithFieldTypeAsObject() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .startObject("type").field("type_field", "type_value").endObject() @@ -1258,7 +1258,7 @@ public void testNoLevelWithFieldTypeAsValueNotFirst() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("test1", "value1") @@ -1280,7 +1280,7 @@ public void testTypeLevelWithFieldTypeAsValueNotFirst() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("test1", "value1") @@ -1302,7 +1302,7 @@ public void testNoLevelWithFieldTypeAsObjectNotFirst() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("test1", "value1") @@ -1325,7 +1325,7 @@ public void testTypeLevelWithFieldTypeAsObjectNotFirst() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject().startObject("type") .field("test1", "value1") @@ -1356,7 +1356,7 @@ public void testDynamicDateDetectionDisabledOnNumbers() throws IOException { // 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(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); Mapping update = doc.dynamicMappingsUpdate(); assertNotNull(update); Mapper dateMapper = update.root().getMapper("foo"); @@ -1378,7 +1378,7 @@ public void testDynamicDateDetectionEnabledWithNoSpecialCharacters() throws IOEx .endObject()); // We should have generated a date field - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON)); Mapping update = doc.dynamicMappingsUpdate(); assertNotNull(update); Mapper dateMapper = update.root().getMapper("foo"); @@ -1481,7 +1481,7 @@ public void testWriteToFieldAlias() throws Exception { .field("alias-field", "value") .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("Cannot write to a field alias [alias-field].", exception.getCause().getMessage()); } @@ -1514,7 +1514,7 @@ public void testCopyToFieldAlias() throws Exception { .field("text-field", "value") .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, bytes, XContentType.JSON))); assertEquals("Cannot copy to a field alias [alias-field].", exception.getCause().getMessage()); } @@ -1545,7 +1545,7 @@ public void testDynamicDottedFieldNameWithFieldAlias() throws Exception { .endObject() .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testTypeless() throws IOException { .field("foo", "1234") .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "_doc", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "_doc", "1", null, 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 23e205b8f58d7..7941bfa91113c 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 void testDoubleIndexingSameDoc() throws Exception { QueryShardContext context = index.newQueryShardContext(0, null, () -> 0L, null); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 8fc03a49c85e2..c07abb866dec7 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 void testDynamicTrue() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(jsonBuilder() .startObject() .field("field1", "value1") @@ -93,7 +93,7 @@ public void testDynamicFalse() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(jsonBuilder() .startObject() .field("field1", "value1") @@ -119,7 +119,7 @@ public void testDynamicStrict() throws IOException { StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(jsonBuilder() + null, BytesReference.bytes(jsonBuilder() .startObject() .field("field1", "value1") .field("field2", "value2") @@ -129,7 +129,7 @@ public void testDynamicStrict() throws IOException { e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", "value1") .field("field2", (String) null) @@ -152,7 +152,7 @@ public void testDynamicFalseWithInnerObjectButDynamicSetOnRoot() throws IOExcept .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(jsonBuilder() + null, BytesReference.bytes(jsonBuilder() .startObject().startObject("obj1") .field("field1", "value1") .field("field2", "value2") @@ -179,7 +179,7 @@ public void testDynamicStrictWithInnerObjectButDynamicSetOnRoot() throws IOExcep StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(jsonBuilder() + null, BytesReference.bytes(jsonBuilder() .startObject().startObject("obj1") .field("field1", "value1") .field("field2", "value2") @@ -208,7 +208,7 @@ private Mapper parse(DocumentMapper mapper, DocumentMapperParser parser, XConten .numberOfShards(1).numberOfReplicas(0).build(); IndexSettings settings = new IndexSettings(build, Settings.EMPTY); SourceToParse source = SourceToParse.source("test", mapper.type(), "some_id", - BytesReference.bytes(builder), builder.contentType()); + null, BytesReference.bytes(builder), builder.contentType()); try (XContentParser xContentParser = createParser(JsonXContent.jsonXContent, source.source())) { ParseContext.InternalParseContext ctx = new ParseContext.InternalParseContext(settings, parser, mapper, source, xContentParser); assertEquals(XContentParser.Token.START_OBJECT, ctx.parser().nextToken()); @@ -561,7 +561,7 @@ public void testMixTemplateMultiFieldAndMappingReuse() throws Exception { XContentBuilder json = XContentFactory.jsonBuilder().startObject() .field("field", "foo") .endObject(); - SourceToParse source = SourceToParse.source("test", "_doc", "1", BytesReference.bytes(json), json.contentType()); + SourceToParse source = SourceToParse.source("test", "_doc", "1", null, BytesReference.bytes(json), json.contentType()); DocumentMapper mapper = indexService.mapperService().documentMapper("_doc"); assertNull(mapper.mappers().getMapper("field.raw")); ParsedDocument parsed = mapper.parse(source); @@ -597,7 +597,7 @@ private void doTestDefaultFloatingPointMappings(DocumentMapper mapper, XContentB .field("quux", "3.2") // float detected through numeric detection .endObject()); ParsedDocument parsedDocument = mapper.parse(SourceToParse.source("index", "type", "id", - source, builder.contentType())); + null, source, builder.contentType())); Mapping update = parsedDocument.dynamicMappingsUpdate(); assertNotNull(update); assertThat(((FieldMapper) update.root().getMapper("foo")).fieldType().typeName(), equalTo("float")); @@ -615,7 +615,7 @@ public void testNumericDetectionEnabled() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("s_long", "100") @@ -642,7 +642,7 @@ public void testNumericDetectionDefault() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("s_long", "100") @@ -691,7 +691,7 @@ public void testDateDetectionInheritsFormat() throws Exception { 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(SourceToParse.source("test", "type", "1", null, 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 fba85b1909cec..892e66f9fd14b 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 void testDynamicMappingDefault() throws IOException { .documentMapperWithAutoCreate("my-type").getDocumentMapper(); ParsedDocument parsedDoc = documentMapper.parse( - SourceToParse.source("my-index", "my-type", "1", BytesReference + SourceToParse.source("my-index", "my-type", "1", null, 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 62c764e8060af..74f1fb571cc17 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 void testMatchTypeOnly() throws Exception { 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(SourceToParse.source("test", "person", "1", null, BytesReference.bytes(builder), XContentType.JSON)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); @@ -70,7 +70,7 @@ public void testSimple() throws Exception { 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(SourceToParse.source("test", "person", "1", null, new BytesArray(json), XContentType.JSON)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); @@ -129,7 +129,7 @@ public void testSimpleWithXContentTraverse() throws Exception { 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(SourceToParse.source("test", "person", "1", null, 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 1d65fb27c55b5..e5ea8cdb21c18 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 void testExternalValues() throws Exception { .endObject().endObject()) )); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -146,7 +146,7 @@ public void testExternalValuesWithMultifield() throws Exception { .endObject() .endObject().endObject().endObject()))); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -213,7 +213,7 @@ public void testExternalValuesWithMultifieldTwoLevels() throws Exception { .endObject() .endObject().endObject().endObject()))); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", null, 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 6d7601357a336..b93e27c45ed05 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java @@ -83,7 +83,7 @@ public void testInjectIntoDocDuringParsing() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("a", "100") .startObject("b") @@ -107,7 +107,7 @@ public void testExplicitEnabled() throws Exception { assertTrue(fieldNamesMapper.fieldType().isEnabled()); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), @@ -126,7 +126,7 @@ public void testDisabled() throws Exception { assertFalse(fieldNamesMapper.fieldType().isEnabled()); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), 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 6999e39b70a7d..05d88a7ef8434 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 void testSimple() throws Exception { 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)); + SourceToParse.source("test", "person", "1", null, 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 a2c17e68b78a5..ac9ec7dea27eb 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java @@ -66,7 +66,7 @@ public void testGeoHashValue() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", stringEncode(1.3, 1.2)) .endObject()), @@ -83,7 +83,7 @@ public void testLatLonValuesStored() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("point").field("lat", 1.2).field("lon", 1.3).endObject() .endObject()), @@ -100,7 +100,7 @@ public void testArrayLatLonValues() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") .startObject().field("lat", 1.2).field("lon", 1.3).endObject() @@ -122,7 +122,7 @@ public void testLatLonInOneValue() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3") .endObject()), @@ -140,7 +140,7 @@ public void testLatLonStringWithZValue() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3,10.0") .endObject()), @@ -158,7 +158,7 @@ public void testLatLonStringWithZValueException() throws Exception { .parse("type", new CompressedXContent(mapping)); SourceToParse source = SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3,10.0") .endObject()), @@ -176,7 +176,7 @@ public void testLatLonInOneValueStored() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3") .endObject()), @@ -192,7 +192,7 @@ public void testLatLonInOneValueArray() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") .value("1.2,1.3") @@ -214,7 +214,7 @@ public void testLonLatArray() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() .endObject()), @@ -232,7 +232,7 @@ public void testLonLatArrayDynamic() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() .endObject()), @@ -249,7 +249,7 @@ public void testLonLatArrayStored() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() .endObject()), @@ -269,7 +269,7 @@ public void testLonLatArrayArrayStored() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") .startArray().value(1.3).value(1.2).endArray() @@ -382,7 +382,7 @@ public void testNullValue() throws Exception { assertThat(nullValue, equalTo(new GeoPoint(1, 2))); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("location") .endObject()), @@ -392,7 +392,7 @@ public void testNullValue() throws Exception { BytesRef defaultValue = doc.rootDoc().getField("location").binaryValue(); doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1, 2") .endObject()), @@ -401,7 +401,7 @@ public void testNullValue() throws Exception { assertThat(defaultValue, equalTo(doc.rootDoc().getField("location").binaryValue())); doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "3, 4") .endObject()), @@ -423,7 +423,7 @@ public void testInvalidGeohashIgnored() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1234.333") .endObject()), @@ -446,7 +446,7 @@ public void testInvalidGeohashNotIgnored() throws Exception { MapperParsingException ex = expectThrows(MapperParsingException.class, () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1234.333") .endObject()), @@ -470,57 +470,57 @@ public void testInvalidGeopointValuesIgnored() throws Exception { .parse("type", new CompressedXContent(mapping)); assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "1234.333").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, 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", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, 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", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "-,1.3").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "1.3,-").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, 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", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, 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", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, 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", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "NaN,NaN").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("location", "10,NaN").endObject() ), XContentType.JSON)).rootDoc().getField("location"), nullValue()); assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, 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 aab5e98ed0a12..651ea361ccd43 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 void testIncludeInObjectNotAllowed() throws Exception { .parse("type", new CompressedXContent(mapping)); try { - docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + docMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("_id", "1").endObject()), XContentType.JSON)); fail("Expected failure to parse metadata field"); } catch (MapperParsingException e) { @@ -63,7 +63,7 @@ public void testDefaults() throws IOException { 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)); + null, new BytesArray("{}"), XContentType.JSON)); IndexableField[] fields = document.rootDoc().getFields(IdFieldMapper.NAME); assertEquals(1, fields.length); assertEquals(IndexOptions.DOCS, fields[0].fieldType().indexOptions()); 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 e60b097aaca36..8aa6f86d710eb 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java @@ -48,7 +48,7 @@ public void testDefaultDisabledIndexMapper() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), 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 c5eded8f5ab11..b7f33e0fbb534 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -97,7 +97,7 @@ public void testNotIndexed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -119,7 +119,7 @@ public void testNoDocValues() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -142,7 +142,7 @@ public void testStore() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -170,7 +170,7 @@ public void testIgnoreMalformed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -185,7 +185,7 @@ public void testIgnoreMalformed() throws Exception { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -210,7 +210,7 @@ public void testNullValue() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -231,7 +231,7 @@ public void testNullValue() throws IOException { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 2c70b25d6a446..9c2db006a155c 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 void testStoreCidr() throws Exception { 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(SourceToParse.source("test", "type", "1", null, 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 8060c0a3f92c8..073799191fb00 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 void testMergeMultiField() throws Exception { 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(); + SourceToParse.source("test", "person", "1", null, json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -61,7 +61,7 @@ public void testMergeMultiField() throws Exception { 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(SourceToParse.source("test", "person", "1", null, json, XContentType.JSON)).rootDoc(); f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -99,7 +99,7 @@ public void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception { 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(); + SourceToParse.source("test", "person", "1", null, json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -117,7 +117,7 @@ public void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception { assertThat(mapperService.fullName("name.not_indexed3"), nullValue()); doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + SourceToParse.source("test", "person", "1", null, 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 8e5c81e58f189..18d8bd9405853 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -147,7 +147,7 @@ public void testIgnoreAbove() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "elk") @@ -157,7 +157,7 @@ public void testIgnoreAbove() throws IOException { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "elasticsearch") @@ -176,7 +176,7 @@ public void testNullValue() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -192,7 +192,7 @@ public void testNullValue() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .endObject()), @@ -201,7 +201,7 @@ public void testNullValue() throws IOException { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -222,7 +222,7 @@ public void testEnableStore() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -243,7 +243,7 @@ public void testDisableIndex() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -265,7 +265,7 @@ public void testDisableDocValues() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -287,7 +287,7 @@ public void testIndexOptions() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -333,7 +333,7 @@ public void testEnableNorms() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -358,7 +358,7 @@ public void testNormalizer() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 8e350cfe1c77d..b08a1eae04d85 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 @@ private void testMultiField(String mapping) throws Exception { 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(); + SourceToParse.source("test", "person", "1", null, json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f.name(), equalTo("name")); @@ -140,7 +140,7 @@ public void testBuildThenParse() throws Exception { 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(SourceToParse.source("test", "person", "1", null, 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 1d339aa9bbb00..2a58bedc6bb5a 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 void testEmptyNested() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -73,7 +73,7 @@ public void testEmptyNested() throws Exception { assertThat(doc.docs().size(), equalTo(1)); - doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -96,7 +96,7 @@ public void testSingleNested() throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -112,7 +112,7 @@ public void testSingleNested() throws Exception { assertThat(doc.docs().get(1).get("field"), equalTo("value")); - doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -155,7 +155,7 @@ public void testMultiNested() throws Exception { assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -216,7 +216,7 @@ public void testMultiObjectAndNested1() throws Exception { assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -279,7 +279,7 @@ public void testMultiObjectAndNested2() throws Exception { assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -340,7 +340,7 @@ public void testMultiRootAndNested1() throws Exception { assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(true)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -399,7 +399,7 @@ public void testMultipleLevelsIncludeRoot1() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().startArray("nested1") .startObject().startArray("nested2").startObject().field("foo", "bar") .endObject().endArray().endObject().endArray() @@ -433,7 +433,7 @@ public void testMultipleLevelsIncludeRoot2() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().startArray("nested1") .startObject().startArray("nested2") .startObject().startArray("nested3").startObject().field("foo", "bar") @@ -461,7 +461,7 @@ public void testNestedArrayStrict() throws Exception { assertThat(nested1Mapper.dynamic(), equalTo(Dynamic.STRICT)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -569,7 +569,7 @@ public void testLimitNestedDocsDefaultSettings() throws Exception{ } docBuilder.endObject(); SourceToParse source1 = SourceToParse.source("test1", "type", "1", - BytesReference.bytes(docBuilder), XContentType.JSON); + null, BytesReference.bytes(docBuilder), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source1)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" + defaultMaxNoNestedDocs @@ -602,7 +602,7 @@ public void testLimitNestedDocs() throws Exception{ } docBuilder.endObject(); SourceToParse source1 = SourceToParse.source("test1", "type", "1", - BytesReference.bytes(docBuilder), XContentType.JSON); + null, BytesReference.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -620,7 +620,7 @@ public void testLimitNestedDocs() throws Exception{ } docBuilder2.endObject(); SourceToParse source2 = SourceToParse.source("test1", "type", "2", - BytesReference.bytes(docBuilder2), XContentType.JSON); + null, BytesReference.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" + maxNoNestedDocs @@ -658,7 +658,7 @@ public void testLimitNestedDocsMultipleNestedFields() throws Exception{ } docBuilder.endObject(); SourceToParse source1 = SourceToParse.source("test1", "type", "1", - BytesReference.bytes(docBuilder), XContentType.JSON); + null, BytesReference.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -681,7 +681,7 @@ public void testLimitNestedDocsMultipleNestedFields() throws Exception{ } docBuilder2.endObject(); SourceToParse source2 = SourceToParse.source("test1", "type", "2", - BytesReference.bytes(docBuilder2), XContentType.JSON); + null, BytesReference.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" + maxNoNestedDocs @@ -715,7 +715,7 @@ public void testReorderParentBWC() throws IOException { assertThat(nested1Mapper.nested().isNested(), equalTo(true)); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") 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 550802f6c9dfd..27b1d803d3b6b 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java @@ -40,7 +40,7 @@ public void testNullValueObject() throws IOException { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("obj1").endObject() .field("value1", "test1") @@ -50,7 +50,7 @@ public void testNullValueObject() throws IOException { assertThat(doc.rootDoc().get("value1"), equalTo("test1")); doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("obj1") .field("value1", "test1") @@ -60,7 +60,7 @@ public void testNullValueObject() throws IOException { assertThat(doc.rootDoc().get("value1"), equalTo("test1")); doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder() + null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("obj1").field("field", "value").endObject() .field("value1", "test1") 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 8b8e174dba83c..c72f1707c2319 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 void doTestDefaults(String type) throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -84,7 +84,7 @@ public void doTestNotIndexed(String type) throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -107,7 +107,7 @@ public void doTestNoDocValues(String type) throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -131,7 +131,7 @@ public void doTestStore(String type) throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -160,7 +160,7 @@ public void doTestCoerce(String type) throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -183,7 +183,7 @@ public void doTestCoerce(String type) throws IOException { assertEquals(mapping, mapper2.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -203,7 +203,7 @@ protected void doTestDecimalCoerce(String type) throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "7.89") @@ -230,7 +230,7 @@ private void doTestIgnoreMalformed(String type) throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "a") @@ -246,7 +246,7 @@ private void doTestIgnoreMalformed(String type) throws IOException { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "a") @@ -308,7 +308,7 @@ protected void doTestNullValue(String type) throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -335,7 +335,7 @@ protected void doTestNullValue(String type) throws IOException { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -422,7 +422,7 @@ public void testOutOfRangeValues() throws IOException { } private void parseRequest(NumberType type, BytesReference content) throws IOException { - createDocumentMapper(type).parse(SourceToParse.source("test", "type", "1", content, XContentType.JSON)); + createDocumentMapper(type).parse(SourceToParse.source("test", "type", "1", null, 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 676cefda36559..21a4cf8ab721c 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 void testDifferentInnerObjectTokenFailure() throws Exception { 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(SourceToParse.source("test", "type", "1", null, 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 9546fb5136e31..20e96e0faf5fe 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 void testSimple() throws Exception { 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)); + SourceToParse.source("test", "person", "1", null, 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 1f8b0b58af813..b16730a586e53 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 void doTestDefaults(String type) throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -152,7 +152,7 @@ protected void doTestNotIndexed(String type) throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -176,7 +176,7 @@ protected void doTestNoDocValues(String type) throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -202,7 +202,7 @@ protected void doTestStore(String type) throws Exception { 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(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -241,7 +241,7 @@ public void doTestCoerce(String type) throws IOException { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -268,7 +268,7 @@ public void doTestCoerce(String type) throws IOException { ThrowingRunnable runnable = () -> mapper2 .parse(SourceToParse.source( - "test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("field") + "test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("field") .field(getFromField(), "5.2").field(getToField(), "10").endObject().endObject()), XContentType.JSON)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); @@ -287,7 +287,8 @@ protected void doTestDecimalCoerce(String type) throws IOException { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", null, + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(GT_FIELD.getPreferredName(), "2.34") @@ -296,7 +297,8 @@ protected void doTestDecimalCoerce(String type) throws IOException { .endObject()), XContentType.JSON)); - ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", null, + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(GT_FIELD.getPreferredName(), "2") @@ -324,7 +326,7 @@ protected void doTestNullValue(String type) throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .nullField(getFromField()) @@ -339,7 +341,7 @@ protected void doTestNullValue(String type) throws IOException { assertThat(storedField.stringValue(), containsString(expected)); // test null max value - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -367,7 +369,7 @@ protected void doTestNullValue(String type) throws IOException { assertThat(storedField.stringValue(), containsString(strVal)); // test null range - doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -394,7 +396,7 @@ public void doTestNoBounds(String type) throws IOException { 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(SourceToParse.source("test", "type", "1", null, 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 11c858545d03f..7351e555ccca0 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 void testRoutingMapper() throws Exception { 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(SourceToParse.source("test", "type", "1", "routing_value", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), - XContentType.JSON).routing("routing_value")); + XContentType.JSON)); assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value")); assertThat(doc.rootDoc().get("field"), equalTo("value")); @@ -54,7 +54,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { .parse("type", new CompressedXContent(mapping)); try { - docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() + docMapper.parse(SourceToParse.source("test", "type", "1", null, 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 baccb4f474ecc..d24b98d8cb709 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java @@ -55,7 +55,7 @@ public void testNoFormat() throws Exception { DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(mapping)); ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("field", "value") .endObject()), XContentType.JSON)); @@ -64,7 +64,7 @@ public void testNoFormat() throws Exception { documentMapper = parser.parse("type", new CompressedXContent(mapping)); doc = documentMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.smileBuilder().startObject() + null, BytesReference.bytes(XContentFactory.smileBuilder().startObject() .field("field", "value") .endObject()), XContentType.SMILE)); @@ -81,7 +81,7 @@ public void testIncludes() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("path1").field("field1", "value1").endObject() .startObject("path2").field("field2", "value2").endObject() .endObject()), @@ -105,7 +105,7 @@ public void testExcludes() throws Exception { .parse("type", new CompressedXContent(mapping)); ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("path1").field("field1", "value1").endObject() .startObject("path2").field("field2", "value2").endObject() .endObject()), @@ -217,7 +217,7 @@ public void testSourceObjectContainsExtraTokens() throws Exception { try { documentMapper.parse(SourceToParse.source("test", "type", "1", - new BytesArray("{}}"), XContentType.JSON)); // extra end object (invalid JSON) + null, new BytesArray("{}}"), XContentType.JSON)); // extra end object (invalid JSON) fail("Expected parse exception"); } catch (MapperParsingException e) { assertNotNull(e.getRootCause()); 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 a07192df8047f..7658ec2cc5a06 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 void testBytesAndNumericRepresentation() throws Exception { 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(SourceToParse.source("test", "type", "1", null, 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 f149620b0287b..c8278017ac1d4 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 void testDefaults() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -135,7 +135,7 @@ public void testEnableStore() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -156,7 +156,7 @@ public void testDisableIndex() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -179,7 +179,7 @@ public void testDisableNorms() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -210,7 +210,7 @@ public void testIndexOptions() throws IOException { 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(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(jsonDoc.endObject()), XContentType.JSON)); for (Map.Entry entry : supportedOptions.entrySet()) { @@ -232,7 +232,7 @@ public void testDefaultPositionIncrementGap() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[] {"a", "b"}) @@ -274,7 +274,7 @@ public void testPositionIncrementGap() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference + SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[]{"a", "b"}) @@ -433,7 +433,7 @@ public void testTermVectors() throws IOException { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", "1234") @@ -765,7 +765,7 @@ public void testFastPhraseMapping() throws IOException { new Term("synfield._index_phrase", "motor dog")}) .build())); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "Some English text that is going to be very useful") @@ -830,7 +830,7 @@ public void testIndexPrefixMapping() throws IOException { 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(SourceToParse.source("test", "type", "1", null, 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 26f2b7fc9239e..e412adc893d85 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 void testDocValuesSingleType() throws Exception { 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(SourceToParse.source("index", "type", "id", null, new BytesArray("{}"), XContentType.JSON)); Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig()); @@ -84,7 +84,7 @@ public void testDefaults() throws IOException { 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(SourceToParse.source("index", "type", "id", null, 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 747d951d5a8cc..8700799015e36 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 void testRecoveryToReplicaThatReceivedExtraDocument() throws Exception { 1, randomNonNegativeLong(), false, - SourceToParse.source("index", "type", "replica", new BytesArray("{}"), XContentType.JSON)); + SourceToParse.source("index", "type", "replica", null, new BytesArray("{}"), XContentType.JSON)); shards.promoteReplicaToPrimary(promotedReplica).get(); oldPrimary.close("demoted", randomBoolean()); oldPrimary.store().close(); @@ -210,7 +210,7 @@ public void testRecoveryToReplicaThatReceivedExtraDocument() throws Exception { promotedReplica.applyIndexOperationOnPrimary( Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("index", "type", "primary", new BytesArray("{}"), XContentType.JSON), + SourceToParse.source("index", "type", "primary", null, 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 0ca449b3ca7d6..264cc9f8a4971 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 void testMaybeFlush() throws Exception { .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), + SourceToParse.source("test", "test", "1", null, 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 void testMaybeRollTranslogGeneration() throws Exception { 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), + SourceToParse.source("test", "test", "1", null, 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 7679595a7fa3b..d274e76629b71 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 void testRecoverFromStoreWithOutOfOrderDelete() throws IOException { 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)); + SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id", null, 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)); + SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-3", null, 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)); + SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-2", null, 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)); + SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-5", null, new BytesArray("{}"), XContentType.JSON)); final int translogOps; if (randomBoolean()) { @@ -1913,7 +1913,7 @@ public void testRecoverFromStoreWithNoOps() throws IOException { final IndexShard otherShard = newStartedShard(false); updateMappings(otherShard, shard.indexSettings().getIndexMetaData()); SourceToParse sourceToParse = SourceToParse.source(shard.shardId().getIndexName(), "_doc", "1", - new BytesArray("{}"), XContentType.JSON); + null, new BytesArray("{}"), XContentType.JSON); otherShard.applyIndexOperationOnReplica(1, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); @@ -2033,11 +2033,11 @@ public void testRecoverFromStoreRemoveStaleOperations() throws Exception { 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)); + SourceToParse.source(indexName, "_doc", "doc-0", null, 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)); + SourceToParse.source(indexName, "_doc", "doc-1", null, 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 void testRecoverFromStoreRemoveStaleOperations() throws Exception { 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)); + SourceToParse.source(indexName, "_doc", "doc-2", null, new BytesArray("{}"), XContentType.JSON)); flushShard(shard); assertThat(getShardDocUIDs(shard), containsInAnyOrder("doc-0", "doc-1", "doc-2")); closeShard(shard, false); @@ -3038,7 +3038,7 @@ private Result indexOnReplicaWithGaps( 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, - new BytesArray("{}"), XContentType.JSON); + null, new BytesArray("{}"), XContentType.JSON); indexShard.applyIndexOperationOnReplica(i, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); if (!gap && i == localCheckpoint + 1) { 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 282404de9a45e..f75234bf73d44 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,8 @@ public void testSyncerSendsOffCorrectDocuments() throws Exception { 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), + SourceToParse.source(shard.shardId().getIndexName(), "_doc", Integer.toString(i), null, + new BytesArray("{}"), XContentType.JSON), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, randomBoolean() ? IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP : randomNonNegativeLong(), true); } @@ -150,7 +151,8 @@ public void testSyncerOnClosingShard() throws Exception { 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), + SourceToParse.source(shard.shardId().getIndexName(), "_doc", Integer.toString(i), null, + 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 694032bd9887a..4e951fccae34f 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 void testRecoveryWithOutOfOrderDeleteWithTranslog() throws Exception { 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)); + SourceToParse.source(indexName, "type", "id", null, 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)); + SourceToParse.source(indexName, "type", "id-3", null, 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)); + SourceToParse.source(indexName, "type", "id-2", null, 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)); + SourceToParse.source(indexName, "type", "id-5", null, new BytesArray("{}"), XContentType.JSON)); final int translogOps; if (randomBoolean()) { @@ -196,19 +196,19 @@ public void testRecoveryWithOutOfOrderDeleteWithSoftDeletes() throws Exception { 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)); + SourceToParse.source(indexName, "type", "id", null, 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)); + SourceToParse.source(indexName, "type", "id-3", null, 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)); + SourceToParse.source(indexName, "type", "id-2", null, 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)); + SourceToParse.source(indexName, "type", "id-5", null, new BytesArray("{}"), XContentType.JSON)); if (randomBoolean()) { if (randomBoolean()) { @@ -312,7 +312,7 @@ public void testPeerRecoverySendSafeCommitInFileBased() throws Exception { 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("{}"), + SourceToParse.source(primaryShard.shardId().getIndexName(), "_doc", Integer.toString(i), null, 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 62db66eacdac9..cbc73644cf01b 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 void testIndexingWithNoContexts() throws Exception { 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(SourceToParse.source("test", "type1", "1", null, BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -116,7 +116,7 @@ public void testIndexingWithSimpleContexts() throws Exception { 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(SourceToParse.source("test", "type1", "1", null, BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -150,7 +150,7 @@ public void testIndexingWithSimpleNumberContexts() throws Exception { 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(SourceToParse.source("test", "type1", "1", null, BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -184,7 +184,7 @@ public void testIndexingWithSimpleBooleanContexts() throws Exception { 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(SourceToParse.source("test", "type1", "1", null, BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -231,7 +231,7 @@ public void testIndexingWithSimpleNULLContexts() throws Exception { .endObject(); Exception e = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON))); + () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testIndexingWithContextList() throws Exception { 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(SourceToParse.source("test", "type1", "1", null, BytesReference .bytes(jsonBuilder() .startObject() .startObject("completion") @@ -284,7 +284,7 @@ public void testIndexingWithMixedTypeContextList() throws Exception { 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(SourceToParse.source("test", "type1", "1", null, BytesReference .bytes(jsonBuilder() .startObject() .startObject("completion") @@ -327,7 +327,7 @@ public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception { .endObject(); Exception e = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON))); + () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testIndexingWithMultipleContexts() throws Exception { .endObject() .endArray() .endObject(); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder), + ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 a745384eb3edb..4f110682be128 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 @@ -64,7 +64,7 @@ public void testIndexingWithNoContexts() throws Exception { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(jsonBuilder() + null, BytesReference.bytes(jsonBuilder() .startObject() .startArray("completion") .startObject() @@ -103,7 +103,7 @@ public void testIndexingWithSimpleContexts() throws Exception { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(jsonBuilder() + null, BytesReference.bytes(jsonBuilder() .startObject() .startArray("completion") .startObject() @@ -139,7 +139,7 @@ public void testIndexingWithContextList() throws Exception { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(jsonBuilder() + null, BytesReference.bytes(jsonBuilder() .startObject() .startObject("completion") .array("input", "suggestion5", "suggestion6", "suggestion7") @@ -196,7 +196,7 @@ public void testIndexingWithMultipleContexts() throws Exception { .endArray() .endObject(); ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - BytesReference.bytes(builder), XContentType.JSON)); + null, 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 711bbc1336c7c..925e7c935ef1f 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 static CheckedBiFunction ne source.endObject(); } source.endObject(); - return nestedMapper.parse(SourceToParse.source("test", "type", docId, BytesReference.bytes(source), XContentType.JSON)); + return nestedMapper.parse(SourceToParse.source("test", "type", docId, null, 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 830fcec3726a0..5a9e0ef1eaebd 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 @@ -122,9 +122,8 @@ private Engine.Operation convertToEngineOp(Translog.Operation operation, Engine. 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(), + source(indexName, index.type(), index.id(), index.routing(), index.source(), + XContentHelper.xContentType(index.source())), 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 0a007f2a18e2c..c7da5bf9f8160 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 @@ protected Engine.IndexResult indexDoc(IndexShard shard, String type, String id, 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 = SourceToParse.source(shard.shardId().getIndexName(), type, id, routing, + new BytesArray(source), xContentType); 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 9428ca8978500..d60f92995fbfc 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 @@ -40,13 +40,13 @@ public void testDoNotFillGaps() throws Exception { for (int i = 0; i < 8; i++) { final String id = Long.toString(i); SourceToParse sourceToParse = SourceToParse.source(indexShard.shardId().getIndexName(), "_doc", id, - new BytesArray("{}"), XContentType.JSON); + null, 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", - new BytesArray("{}"), XContentType.JSON); + null, new BytesArray("{}"), XContentType.JSON); indexShard.applyIndexOperationOnReplica(seqNo, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); // promote the replica to primary: 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 f1de51c95b6e9..f564878d6936a 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 @@ -293,9 +293,9 @@ public IndexShard reindex(DirectoryReader reader, MappingMetaData mapping) throw 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, + source(index, uid.type(), uid.id(), rootFieldsVisitor.routing(), source, XContentHelper.xContentType(source)), + 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()); From 01c3467836641df4365013172b4c3511242f5b5b Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Mon, 24 Dec 2018 11:24:01 -0500 Subject: [PATCH 2/2] Two ctors --- .../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 | 64 ++++---- .../percolator/PercolateQueryBuilder.java | 4 +- .../PercolatorFieldMapperTests.java | 56 +++---- .../ICUCollationKeywordFieldMapperTests.java | 22 +-- .../AnnotatedTextFieldMapperTests.java | 18 +-- .../murmur3/Murmur3FieldMapperTests.java | 3 +- .../index/mapper/size/SizeMappingTests.java | 6 +- .../action/bulk/TransportShardBulkAction.java | 9 +- .../index/mapper/DocumentMapper.java | 4 +- .../index/mapper/SourceToParse.java | 18 +-- .../elasticsearch/index/shard/IndexShard.java | 9 +- .../index/termvectors/TermVectorsService.java | 14 +- .../fielddata/BinaryDVFieldDataTests.java | 8 +- .../index/mapper/BinaryFieldMapperTests.java | 4 +- .../index/mapper/BooleanFieldMapperTests.java | 8 +- .../index/mapper/CamelCaseFieldNameTests.java | 4 +- .../mapper/CompletionFieldMapperTests.java | 88 +++++------ .../index/mapper/CopyToMapperTests.java | 18 +-- .../index/mapper/DateFieldMapperTests.java | 24 +-- .../index/mapper/DocumentMapperTests.java | 8 +- .../index/mapper/DocumentParserTests.java | 138 +++++++++--------- .../index/mapper/DoubleIndexingDocTests.java | 2 +- .../index/mapper/DynamicMappingTests.java | 36 ++--- .../mapper/DynamicMappingVersionTests.java | 2 +- .../index/mapper/DynamicTemplatesTests.java | 6 +- .../mapper/ExternalFieldMapperTests.java | 6 +- .../mapper/FieldNamesFieldMapperTests.java | 12 +- .../GenericStoreDynamicTemplateTests.java | 2 +- .../mapper/GeoPointFieldMapperTests.java | 112 +++++++------- .../index/mapper/IdFieldMapperTests.java | 6 +- .../index/mapper/IndexFieldMapperTests.java | 4 +- .../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 | 60 ++++---- .../mapper/NullValueObjectMappingTests.java | 12 +- .../index/mapper/NumberFieldMapperTests.java | 24 +-- .../index/mapper/ObjectMapperTests.java | 2 +- .../mapper/PathMatchDynamicTemplateTests.java | 2 +- .../index/mapper/RangeFieldMapperTests.java | 28 ++-- .../index/mapper/RoutingFieldMapperTests.java | 6 +- .../index/mapper/SourceFieldMapperTests.java | 20 +-- .../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 | 22 +-- .../shard/PrimaryReplicaSyncerTests.java | 6 +- .../indices/recovery/RecoveryTests.java | 18 +-- .../CategoryContextMappingTests.java | 18 +-- .../completion/GeoContextMappingTests.java | 16 +- .../index/engine/EngineTestCase.java | 2 +- .../index/engine/TranslogHandler.java | 6 +- .../index/shard/IndexShardTestCase.java | 4 +- .../engine/FollowEngineIndexShardTests.java | 8 +- .../SourceOnlySnapshotShardTests.java | 7 +- 66 files changed, 555 insertions(+), 563 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 7ebe29e857934..d8815ef9026c4 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 @@ private static Response prepareRamIndex(Request request, String type = indexService.mapperService().documentMapper().type(); BytesReference document = request.contextSetup.document; XContentType xContentType = request.contextSetup.xContentType; - SourceToParse sourceToParse = SourceToParse.source(index, type, "_id", null, document, xContentType); + SourceToParse sourceToParse = new SourceToParse(index, type, "_id", document, xContentType); ParsedDocument parsedDocument = indexService.mapperService().documentMapper().parse(sourceToParse); indexWriter.addDocuments(parsedDocument.docs()); try (IndexReader indexReader = DirectoryReader.open(indexWriter)) { diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/DenseVectorFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/DenseVectorFieldMapperTests.java index dc81f6fd5c6b5..2239c99a310f5 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/DenseVectorFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/DenseVectorFieldMapperTests.java @@ -58,7 +58,7 @@ public void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); float[] expectedArray = {-12.1f, 100.7f, -4}; - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test-index", "_doc", "1", null, BytesReference + ParsedDocument doc1 = mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startArray("my-dense-vector").value(expectedArray[0]).value(expectedArray[1]).value(expectedArray[2]).endArray() diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureFieldMapperTests.java index e8ecf7143871e..73879bb0225b9 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/FeatureFieldMapperTests.java @@ -72,7 +72,7 @@ public void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 10) @@ -84,7 +84,7 @@ public void testDefaults() throws Exception { assertThat(fields[0], Matchers.instanceOf(FeatureField.class)); FeatureField featureField1 = (FeatureField) fields[0]; - ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc2 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 12) @@ -108,7 +108,7 @@ public void testNegativeScoreImpact() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 10) @@ -120,7 +120,7 @@ public void testNegativeScoreImpact() throws Exception { assertThat(fields[0], Matchers.instanceOf(FeatureField.class)); FeatureField featureField1 = (FeatureField) fields[0]; - ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc2 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 12) @@ -145,7 +145,7 @@ public void testRejectMultiValuedFields() throws MapperParsingException, IOExcep assertEquals(mapping, mapper.mappingSource().toString()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", Arrays.asList(10, 20)) @@ -155,7 +155,7 @@ public void testRejectMultiValuedFields() throws MapperParsingException, IOExcep e.getCause().getMessage()); e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 8abfefe91888a..852b6f6fc3c5c 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") @@ -95,7 +95,7 @@ public void testRejectMultiValuedFields() throws MapperParsingException, IOExcep assertEquals(mapping, mapper.mappingSource().toString()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") @@ -107,7 +107,7 @@ public void testRejectMultiValuedFields() throws MapperParsingException, IOExcep "START_ARRAY", e.getCause().getMessage()); e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 dc3c5c49eb3dc..366f9a2e5745b 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -115,7 +115,7 @@ public void testNotIndexed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -139,7 +139,7 @@ public void testNoDocValues() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -163,7 +163,7 @@ public void testStore() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -192,7 +192,7 @@ public void testCoerce() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -216,7 +216,7 @@ public void testCoerce() throws Exception { assertEquals(mapping, mapper2.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ThrowingRunnable runnable = () -> mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -245,7 +245,7 @@ private void doTestIgnoreMalformed(String value, String exceptionMessageContains assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", value) @@ -261,7 +261,7 @@ private void doTestIgnoreMalformed(String value, String exceptionMessageContains DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", value) @@ -286,7 +286,7 @@ public void testNullValue() throws IOException { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -308,7 +308,7 @@ public void testNullValue() throws IOException { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 b9e3f921cfa5d..06710e39592cc 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 @@ protected Collection> getPlugins() { 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", null, 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 void testDefaults() throws Exception { public void testErrors() { // 1. test for an error on negative dimension MapperParsingException e = expectThrows(MapperParsingException.class, () -> { - mapper.parse(SourceToParse.source("test-index", "_doc", "1", null, BytesReference + mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -118,7 +118,7 @@ public void testErrors() { // 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", null, BytesReference + mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -133,7 +133,7 @@ public void testErrors() { // 3. test for an error on a wrong formatted dimension e = expectThrows(MapperParsingException.class, () -> { - mapper.parse(SourceToParse.source("test-index", "_doc", "1", null, BytesReference + mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .startObject("my-sparse-vector") @@ -148,7 +148,7 @@ public void testErrors() { // 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", null, 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 bb82946bf081a..1965cbad06673 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 @@ private SourceToParse createDocument(String fieldValue) throws Exception { .field("test", fieldValue) .endObject()); - return SourceToParse.source("test", "person", "1", null, 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 cc19f602d1aca..5c20969b53fb8 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,33 +63,33 @@ public void testSingleLevel() throws Exception { assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService())); // Doc without join - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)); + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "parent") .endObject()), XContentType.JSON)); assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); // Doc child - doc = docMapper.parse(SourceToParse.source("test", "type", "2", - "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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)); + .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", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + () -> docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "unknown") .endObject()), XContentType.JSON))); assertThat(exc.getRootCause().getMessage(), containsString("unknown join name [unknown] for field [join_field]")); @@ -109,22 +109,22 @@ public void testParentIdSpecifiedAsNumber() throws Exception { 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", - "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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)); + .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", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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)); + .endObject()), XContentType.JSON, "1")); assertEquals("1.0", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); } @@ -147,13 +147,13 @@ public void testMultipleLevels() throws Exception { assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService())); // Doc without join - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)); + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("join_field", "parent") .endObject()), XContentType.JSON)); @@ -161,29 +161,29 @@ public void testMultipleLevels() throws Exception { assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); // Doc child - doc = docMapper.parse(SourceToParse.source("test", "type", "2", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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)); + .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", - "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + () -> docMapper.parse(new SourceToParse("test", "type", "2", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "child") - .endObject()), XContentType.JSON))); + .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", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + () -> docMapper.parse(new SourceToParse("test", "type", "2", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .startObject("join_field") .field("name", "child") .field("parent", "1") @@ -192,20 +192,20 @@ public void testMultipleLevels() throws Exception { assertThat(exc.getRootCause().getMessage(), containsString("[routing] is missing for join field [join_field]")); // Doc grand_child - doc = docMapper.parse(SourceToParse.source("test", "type", "3", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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)); + .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", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + () -> docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("join_field", "unknown") .endObject()), XContentType.JSON))); assertThat(exc.getRootCause().getMessage(), containsString("unknown join name [unknown] for field [join_field]")); 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 78324ab7aef42..2cb37cb794dda 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.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.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 @@ protected Query doToQuery(QueryShardContext context) throws IOException { } docMapper = mapperService.documentMapper(type); for (BytesReference document : documents) { - docs.add(docMapper.parse(source(context.index().getName(), type, "_temp_id", null, document, documentXContentType))); + docs.add(docMapper.parse(new SourceToParse(context.index().getName(), type, "_temp_id", document, documentXContentType))); } FieldNameAnalyzer fieldNameAnalyzer = (FieldNameAnalyzer) docMapper.mappers().indexAnalyzer(); diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java index 8df004ac68adb..3030e48690fe9 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java @@ -479,8 +479,8 @@ public void testExtractTermsAndRanges_numberFields() throws Exception { public void testPercolatorFieldMapper() throws Exception { addQueryFieldMappings(); QueryBuilder queryBuilder = termQuery("field", "value"); - ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - null, BytesReference.bytes(XContentFactory + ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", + BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .field(fieldName, queryBuilder) @@ -498,7 +498,7 @@ public void testPercolatorFieldMapper() throws Exception { // add an query for which we don't extract terms from queryBuilder = rangeQuery("field").from("a").to("z"); - doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", null, BytesReference.bytes(XContentFactory + doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .field(fieldName, queryBuilder) @@ -524,8 +524,8 @@ public void testStoringQueries() throws Exception { // (it can't use shard data for rewriting purposes, because percolator queries run on MemoryIndex) for (QueryBuilder query : queries) { - ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, query) .endObject()), XContentType.JSON)); @@ -538,8 +538,8 @@ public void testQueryWithRewrite() throws Exception { addQueryFieldMappings(); client().prepareIndex("remote", "doc", "1").setSource("field", "value").get(); QueryBuilder queryBuilder = termsLookupQuery("field", new TermsLookup("remote", "doc", "1", "field")); - ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - null, BytesReference.bytes(XContentFactory + ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", + BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .field(fieldName, queryBuilder) @@ -559,7 +559,7 @@ public void testQueryWithRewrite() throws Exception { public void testPercolatorFieldMapperUnMappedField() throws Exception { addQueryFieldMappings(); MapperParsingException exception = expectThrows(MapperParsingException.class, () -> { - mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", null, 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 void testPercolatorFieldMapperUnMappedField() throws Exception { public void testPercolatorFieldMapper_noQuery() throws Exception { addQueryFieldMappings(); - ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", null, BytesReference + ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference .bytes(XContentFactory .jsonBuilder() .startObject() @@ -582,7 +582,7 @@ public void testPercolatorFieldMapper_noQuery() throws Exception { assertThat(doc.rootDoc().getFields(fieldType.queryBuilderField.name()).length, equalTo(0)); try { - mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", null, BytesReference.bytes(XContentFactory + mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory .jsonBuilder() .startObject() .nullField(fieldName) @@ -619,8 +619,8 @@ public void testMultiplePercolatorFields() throws Exception { 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", - null, BytesReference.bytes(jsonBuilder().startObject() + ParsedDocument doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", + BytesReference.bytes(jsonBuilder().startObject() .field("query_field1", queryBuilder) .field("query_field2", queryBuilder) .endObject()), @@ -650,8 +650,8 @@ public void testNestedPercolatorField() throws Exception { 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", - null, BytesReference.bytes(jsonBuilder().startObject().startObject("object_field") + ParsedDocument doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", + BytesReference.bytes(jsonBuilder().startObject().startObject("object_field") .field("query_field", queryBuilder) .endObject().endObject()), XContentType.JSON)); @@ -659,8 +659,8 @@ public void testNestedPercolatorField() throws Exception { 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", - null, BytesReference.bytes(jsonBuilder().startObject() + doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", + BytesReference.bytes(jsonBuilder().startObject() .startArray("object_field") .startObject().field("query_field", queryBuilder).endObject() .endArray() @@ -671,8 +671,8 @@ public void testNestedPercolatorField() throws Exception { assertQueryBuilder(queryBuilderAsBytes, queryBuilder); MapperParsingException e = expectThrows(MapperParsingException.class, () -> { - mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", - null, BytesReference.bytes(jsonBuilder().startObject() + mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", + BytesReference.bytes(jsonBuilder().startObject() .startArray("object_field") .startObject().field("query_field", queryBuilder).endObject() .startObject().field("query_field", queryBuilder).endObject() @@ -756,8 +756,8 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { query.endObject(); query.endObject(); - ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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()), XContentType.JSON)); @@ -794,8 +794,8 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { query.endObject(); query.endObject(); - doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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()), XContentType.JSON)); @@ -880,8 +880,8 @@ public void testDuplicatedClauses() throws Exception { 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), XContentType.JSON)); @@ -902,8 +902,8 @@ public void testDuplicatedClauses() throws Exception { .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", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), XContentType.JSON)); @@ -927,8 +927,8 @@ public void testDuplicatedClauses() throws Exception { .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", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field(fieldName, qb) .endObject()), XContentType.JSON)); 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 c8e386b4b2ca7..103098d5a4620 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -112,7 +112,7 @@ public void testNullValue() throws IOException { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -129,7 +129,7 @@ public void testNullValue() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .endObject()), @@ -138,7 +138,7 @@ public void testNullValue() throws IOException { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -164,7 +164,7 @@ public void testEnableStore() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -186,7 +186,7 @@ public void testDisableIndex() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -209,7 +209,7 @@ public void testDisableDocValues() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -230,7 +230,7 @@ public void testMultipleValues() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testIndexOptions() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -326,7 +326,7 @@ public void testEnableNorms() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -350,7 +350,7 @@ public void testCollator() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 b730f9575eeca..aa0dbe07c8305 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 void testAnnotationInjection() throws IOException { // 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", null, BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", annotatedText) @@ -171,7 +171,7 @@ public void testToleranceForBadAnnotationMarkup() throws IOException { new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); String annotatedText = "foo [bar](MissingEndBracket baz"; - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", annotatedText) @@ -260,7 +260,7 @@ public void testDefaults() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -292,7 +292,7 @@ public void testEnableStore() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -316,7 +316,7 @@ public void testDisableNorms() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -347,7 +347,7 @@ public void testIndexOptions() throws IOException { for (String option : supportedOptions.keySet()) { jsonDoc.field(option, "1234"); } - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDefaultPositionIncrementGap() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[] {"a", "b"}) @@ -411,7 +411,7 @@ public void testPositionIncrementGap() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[]{"a", "b"}) @@ -570,7 +570,7 @@ public void testTermVectors() throws IOException { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 e1400d252b5ac..a26e2a4872841 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,8 +78,7 @@ public void testDefaults() throws Exception { .field("type", "murmur3") .endObject().endObject().endObject().endObject()); DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument parsedDoc = mapper.parse(SourceToParse.source("test", "type", "1", null, - 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 52c3429e476ee..58d9b696f6a4e 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 void testSizeEnabled() throws Exception { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testSizeDisabled() throws Exception { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testSizeNotSet() throws Exception { .startObject() .field("field", "value") .endObject()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, 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 f518eaf9b8282..d56cd5c8cbce3 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -420,9 +420,8 @@ private static Engine.Result performOpOnReplica(DocWriteResponse primaryResponse case INDEX: final IndexRequest indexRequest = (IndexRequest) docWriteRequest; final ShardId shardId = replica.shardId(); - final SourceToParse sourceToParse = - SourceToParse.source(shardId.getIndexName(), indexRequest.type(), indexRequest.id(), indexRequest.routing(), - indexRequest.source(), indexRequest.getContentType()); + final SourceToParse sourceToParse = new SourceToParse(shardId.getIndexName(), indexRequest.type(), indexRequest.id(), + indexRequest.source(), indexRequest.getContentType(), indexRequest.routing()); result = replica.applyIndexOperationOnReplica(primaryResponse.getSeqNo(), primaryResponse.getVersion(), indexRequest.getAutoGeneratedTimestamp(), indexRequest.isRetry(), sourceToParse); break; @@ -455,8 +454,8 @@ private static void executeIndexRequestOnPrimary(BulkPrimaryExecutionContext con MappingUpdatePerformer mappingUpdater) throws Exception { final IndexRequest request = context.getRequestToExecute(); final IndexShard primary = context.getPrimary(); - final SourceToParse sourceToParse = SourceToParse.source(request.index(), request.type(), request.id(), request.routing(), - request.source(), request.getContentType()); + final SourceToParse sourceToParse = + new SourceToParse(request.index(), request.type(), request.id(), request.source(), request.getContentType(), request.routing()); executeOnPrimaryWhileHandlingMappingUpdates(context, () -> 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 413717d6b08f2..058cf68e8e1f4 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 ParsedDocument parse(SourceToParse source) throws MapperParsingException } public ParsedDocument createDeleteTombstoneDoc(String index, String type, String id) throws MapperParsingException { - final SourceToParse emptySource = SourceToParse.source(index, type, id, null, 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, null, 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 446d117a1d403..7cb3241d61f70 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 @@ 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, String routing, BytesReference source, - XContentType contentType) { - return new SourceToParse(index, type, id, routing, source, contentType); - } - private final BytesReference source; private final String index; @@ -40,19 +36,23 @@ public static SourceToParse source(String index, String type, String id, String private final String id; - private final String routing; + private final @Nullable String routing; private final XContentType xContentType; - public SourceToParse(String index, String type, String id, String routing, 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); - this.routing = routing; // we always convert back to byte array, since we store it and Field only supports bytes.. // 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() { @@ -71,7 +71,7 @@ public String id() { return this.id; } - public String routing() { + public @Nullable String routing() { return this.routing; } 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 0d6bd8dc853e6..06d9bb4018ffa 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.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,8 +714,8 @@ private Engine.IndexResult applyIndexOperation(Engine engine, long seqNo, long o if (resolvedType.equals(sourceToParse.type())) { sourceWithResolvedType = sourceToParse; } else { - sourceWithResolvedType = SourceToParse.source(sourceToParse.index(), resolvedType, sourceToParse.id(), - sourceToParse.routing(), sourceToParse.source(), sourceToParse.getXContentType()); + 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); @@ -1299,8 +1298,8 @@ private Engine.Result applyTranslogOperation(Engine engine, Translog.Operation o // 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.routing(), index.source(), - XContentHelper.xContentType(index.source()))); + 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 d03c2c9257bd3..a05870b842f2d 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.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.concurrent.TimeUnit; import java.util.function.LongSupplier; -import static org.elasticsearch.index.mapper.SourceToParse.source; - public class TermVectorsService { @@ -302,8 +301,8 @@ private static Fields generateTermVectors(IndexShard indexShard, 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.routing(), - 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(); @@ -331,11 +330,12 @@ private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVect request.offsets(), request.perFieldAnalyzer(), seenFields); } - private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, String routing, - BytesReference doc, XContentType xContentType) { + private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc, + 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", null, 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 f140f4e8d915c..023a0a84f53a2 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 void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - ParsedDocument d = mapper.parse(SourceToParse.source("test", "test", "1", null, 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", null, 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", null, 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 void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - d = mapper.parse(SourceToParse.source("test", "test", "4", null, 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 fc0bfc5a03065..3d8c348acab94 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java @@ -91,8 +91,8 @@ public void testStoredValue() throws IOException { assertTrue(CompressorFactory.isCompressed(new BytesArray(binaryValue2))); for (byte[] value : Arrays.asList(binaryValue1, binaryValue2)) { - ParsedDocument doc = mapperService.documentMapper().parse(SourceToParse.source("test", "type", "id", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), + 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"); assertEquals(new BytesRef(value), indexedValue); 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 96658a2fb8c65..f672a955cff18 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 void testDefaults() throws IOException { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", true) @@ -141,7 +141,7 @@ public void testParsesBooleansStrict() throws IOException { .field("field", randomFrom("off", "no", "0", "on", "yes", "1")) .endObject()); MapperParsingException ex = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testMultiFields() throws IOException { .startObject() .field("field", false) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDocValues() throws Exception { DocumentMapper defaultMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); - ParsedDocument parsedDoc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 671c4992b0ca3..83aca847fa4b8 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java @@ -35,8 +35,8 @@ public void testCamelCaseFieldNameStaysAsIs() throws Exception { 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("thisIsCamelCase", "value1") .endObject()), XContentType.JSON)); 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 558f0f4eb3a77..7354af17043eb 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java @@ -166,8 +166,8 @@ public void testParsingMinimal() throws Exception { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", "suggestion") .endObject()), @@ -187,8 +187,8 @@ public void testParsingFailure() throws Exception { .parse("type1", new CompressedXContent(mapping)); MapperParsingException e = expectThrows(MapperParsingException.class, () -> - defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", 1.0) .endObject()), @@ -220,8 +220,8 @@ public void testKeywordWithSubCompletionAndContext() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("keywordfield", "key1", "key2", "key3") .endObject()), @@ -275,8 +275,8 @@ public void testCompletionWithContextAndSubCompletion() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("suggest") .array("input","timmy","starbucks") @@ -331,8 +331,8 @@ public void testCompletionWithContextAndSubCompletionIndexByPath() throws Except DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("suggest", "timmy","starbucks") .array("cat","cafe","food") @@ -368,8 +368,8 @@ public void testKeywordWithSubCompletionAndStringInsert() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("geofield", "drm3btev3e86")//"41.12,-71.34" .endObject()), @@ -399,8 +399,8 @@ public void testCompletionTypeWithSubCompletionFieldAndStringInsert() throws Exc DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("suggest", "suggestion") .endObject()), @@ -431,8 +431,8 @@ public void testCompletionTypeWithSubCompletionFieldAndObjectInsert() throws Exc DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .array("input","New York", "NY") @@ -469,8 +469,8 @@ public void testCompletionTypeWithSubKeywordFieldAndObjectInsert() throws Except DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .array("input","New York", "NY") @@ -509,8 +509,8 @@ public void testCompletionTypeWithSubKeywordFieldAndStringInsert() throws Except DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", "suggestion") .endObject()), @@ -537,8 +537,8 @@ public void testParsingMultiValued() throws Exception { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("completion", "suggestion1", "suggestion2") .endObject()), @@ -561,8 +561,8 @@ public void testParsingWithWeight() throws Exception { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .field("input", "suggestion") @@ -587,8 +587,8 @@ public void testParsingMultiValueWithWeight() throws Exception { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .array("input", "suggestion1", "suggestion2", "suggestion3") @@ -630,8 +630,8 @@ public void testParsingWithGeoFieldAlias() throws Exception { 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("completion") .field("input", "suggestion") @@ -655,8 +655,8 @@ public void testParsingFull() throws Exception { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("completion") .startObject() @@ -693,8 +693,8 @@ public void testParsingMixed() throws Exception { .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("completion"); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("completion") .startObject() @@ -733,8 +733,8 @@ public void testNonContextEnabledParsingWithContexts() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); try { - defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field1") .field("input", "suggestion1") @@ -764,8 +764,8 @@ public void testFieldValueValidation() throws Exception { charsRefBuilder.append("sugg"); charsRefBuilder.setCharAt(2, '\u001F'); try { - defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) .endObject()), @@ -779,8 +779,8 @@ public void testFieldValueValidation() throws Exception { charsRefBuilder.setCharAt(2, '\u0000'); try { - defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) .endObject()), @@ -794,8 +794,8 @@ public void testFieldValueValidation() throws Exception { charsRefBuilder.setCharAt(2, '\u001E'); try { - defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("completion", charsRefBuilder.get().toString()) .endObject()), @@ -808,8 +808,8 @@ public void testFieldValueValidation() throws Exception { } // empty inputs are ignored - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .array("completion", " ", "") .endObject()), @@ -821,8 +821,8 @@ public void testFieldValueValidation() throws Exception { assertThat(ignoredFields.stringValue(), equalTo("completion")); // null inputs are ignored - ParsedDocument nullDoc = defaultMapper.parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument nullDoc = defaultMapper.parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("completion") .endObject()), 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 251d7e5a9ba28..8a7a42e18f040 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 void testCopyToFieldsParsing() throws Exception { .field("int_to_str_test", 42) .endObject()); - ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToFieldsInnerObjectParsing() throws Exception { .startObject("foo").startObject("bar").field("baz", "zoo").endObject().endObject() .endObject()); - ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToDynamicInnerObjectParsing() throws Exception { .field("new_field", "bar") .endObject()); - ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToDynamicInnerInnerObjectParsing() throws Exception { .field("new_field", "bar") .endObject()); - ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToStrictDynamicInnerObjectParsing() throws Exception { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testCopyToInnerStrictDynamicInnerObjectParsing() throws Exception { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", null, json, XContentType.JSON)).rootDoc(); + docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc(); fail(); } catch (MapperParsingException ex) { assertThat(ex.getMessage(), @@ -393,8 +393,8 @@ public void testCopyToNestedField() throws Exception { .endArray() .endObject(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(jsonDoc), XContentType.JSON)); + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(jsonDoc), XContentType.JSON)); assertEquals(6, doc.docs().size()); Document nested = doc.docs().get(0); @@ -562,7 +562,7 @@ public void testCopyToDynamicNestedObjectParsing() throws Exception { .endObject()); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 3f9f5f1df3ee5..8b437d25a8495 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testNotIndexed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testNoDocValues() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testStore() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testIgnoreMalformed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testIgnoreMalformed() throws Exception { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -204,7 +204,7 @@ public void testChangeFormat() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 1457654400) @@ -230,7 +230,7 @@ public void testFloatEpochFormat() throws IOException { long epochMillis = randomNonNegativeLong(); String epochFloatValue = epochMillis + "." + randomIntBetween(0, 999); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", epochFloatValue) @@ -252,7 +252,7 @@ public void testChangeLocale() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 1457654400) @@ -273,7 +273,7 @@ public void testNullValue() throws IOException { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -294,7 +294,7 @@ public void testNullValue() throws IOException { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -363,7 +363,7 @@ public void testTimeZoneParsing() throws Exception { 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", null, 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 87871b63854e2..ff35e93204ac1 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java @@ -177,10 +177,10 @@ public void run() { 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, - null, new BytesArray("{ \"" + fieldName + "\" : \"test\" }"), + new BytesArray("{ \"" + fieldName + "\" : \"test\" }"), XContentType.JSON)); Mapping update = doc.dynamicMappingsUpdate(); assert update != null; @@ -200,10 +200,10 @@ null, new BytesArray("{ \"" + fieldName + "\" : \"test\" }"), 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", - null, source, + source, XContentType.JSON)); if (parsedDoc.dynamicMappingsUpdate() != null) { // not in the mapping yet, try again 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 0737f92dc136d..ffdb93474c0e9 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 void testFieldDisabled() throws Exception { .field("foo", "1234") .field("bar", 10) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDotsWithExistingMapper() throws Exception { .field("baz", 789) .endObject() .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDotsWithExistingNestedMapper() throws Exception { .field("foo.bar", 123) .endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testUnexpectedFieldMappingType() throws Exception { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("foo", true) .endObject()); MapperException exception = expectThrows(MapperException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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", null, 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", null, 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 void testDotsWithDynamicNestedMapper() throws Exception { .field("foo.bar",42) .endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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,8 +225,8 @@ public void testNestedHaveIdAndTypeFields() throws Exception { 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", - null, BytesReference.bytes(doc), XContentType.JSON)); + ParsedDocument result = mapper.parse(new SourceToParse("index2", "type", "1", + BytesReference.bytes(doc), XContentType.JSON)); assertEquals(2, result.docs().size()); // Nested document: assertNotNull(result.docs().get(0).getField(IdFieldMapper.NAME)); @@ -258,7 +258,7 @@ public void testPropagateDynamicWithExistingMapper() throws Exception { .startObject().startObject("foo") .field("bar", "something") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testPropagateDynamicWithDynamicMapper() throws Exception { .startObject().startObject("foo").startObject("bar") .field("baz", "something") .endObject().endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicRootFallback() throws Exception { .startObject().startObject("foo") .field("bar", "something") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicGeoPointArrayWithTemplate() throws Exception { .startArray().value(0).value(0).endArray() .startArray().value(1).value(1).endArray() .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicLongArrayWithTemplate() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicStrictLongArray() throws Exception { .value(1) .endArray().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testMappedGeoPointArray() throws Exception { .startArray().value(0).value(0).endArray() .startArray().value(1).value(1).endArray() .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testMappedLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicObjectWithTemplate() throws Exception { .startObject().startObject("foo") .field("bar", "baz") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseObject() throws Exception { .startObject().startObject("foo") .field("bar", "baz") .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicStrictObject() throws Exception { .field("bar", "baz") .endObject().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseValue() throws Exception { .startObject() .field("bar", "baz") .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicStrictValue() throws Exception { .field("bar", "baz") .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseNull() throws Exception { .startObject() .field("bar", (String) null) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicStrictNull() throws Exception { .field("bar", (String) null) .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testMappedNullValue() throws Exception { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo", (Long) null) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongArrayWithParentTemplate() throws Excep .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongArrayWithExistingParent() throws Excep .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongArrayWithExistingParentWrongType() thr .value(1) .endArray().endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseDottedFieldNameLongArray() throws Exception { .value(0) .value(1) .endArray().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicStrictDottedFieldNameLongArray() throws Exception { .value(1) .endArray().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLong() throws Exception { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongWithParentTemplate() throws Exception BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongWithExistingParent() throws Exception BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameLongWithExistingParentWrongType() throws E .startObject().field("foo.bar.baz", 0) .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicFalseDottedFieldNameLong() throws Exception { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicStrictDottedFieldNameLong() throws Exception { .startObject().field("foo.bar.baz", 0) .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameObject() throws Exception { .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameObjectWithParentTemplate() throws Exceptio .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameObjectWithExistingParent() throws Exceptio 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", null, 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 void testDynamicDottedFieldNameObjectWithExistingParentWrongType() throws 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", null, 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 void testDynamicFalseDottedFieldNameObject() throws Exception { .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicStrictDottedFieldNameObject() throws Exception { .field("a", 0) .endObject().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDocumentContainsMetadataField() throws Exception { BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("_ttl", 0).endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, () -> - mapper.parse(SourceToParse.source("test", "type", "1", null, 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", null, 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 void testSimpleMapper() throws Exception { 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", null, 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", null, 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 void testParseToJsonAndParse() throws Exception { // 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", null, 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 void testSimpleParser() throws Exception { 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", null, 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 void testSimpleParserNoTypeNoId() throws Exception { 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", null, 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 void testNoDocumentSent() throws Exception { BytesReference json = new BytesArray("".getBytes(StandardCharsets.UTF_8)); try { - docMapper.parse(SourceToParse.source("test", "person", "1", null, 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 void testNoLevel() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("test1", "value1") @@ -1150,7 +1150,7 @@ public void testTypeLevel() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testNoLevelWithFieldTypeAsValue() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("type", "value_type") @@ -1192,7 +1192,7 @@ public void testTypeLevelWithFieldTypeAsValue() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testNoLevelWithFieldTypeAsObject() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testTypeLevelWithFieldTypeAsObject() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testNoLevelWithFieldTypeAsValueNotFirst() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testTypeLevelWithFieldTypeAsValueNotFirst() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testNoLevelWithFieldTypeAsObjectNotFirst() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("test1", "value1") @@ -1325,7 +1325,7 @@ public void testTypeLevelWithFieldTypeAsObjectNotFirst() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(defaultMapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDateDetectionDisabledOnNumbers() throws IOException { // 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", null, 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 void testDynamicDateDetectionEnabledWithNoSpecialCharacters() throws IOEx .endObject()); // We should have generated a date field - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testWriteToFieldAlias() throws Exception { .field("alias-field", "value") .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testCopyToFieldAlias() throws Exception { .field("text-field", "value") .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDynamicDottedFieldNameWithFieldAlias() throws Exception { .endObject() .endObject()); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testTypeless() throws IOException { .field("foo", "1234") .endObject()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "_doc", "1", null, 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 7941bfa91113c..2eea666e8fe27 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 void testDoubleIndexingSameDoc() throws Exception { QueryShardContext context = index.newQueryShardContext(0, null, () -> 0L, null); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 c07abb866dec7..56e6f5e4c6b04 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 void testDynamicTrue() throws IOException { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(jsonBuilder() .startObject() .field("field1", "value1") @@ -93,7 +93,7 @@ public void testDynamicFalse() throws IOException { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(jsonBuilder() .startObject() .field("field1", "value1") @@ -118,8 +118,8 @@ public void testDynamicStrict() throws IOException { .parse("type", new CompressedXContent(mapping)); StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(jsonBuilder() + () -> defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(jsonBuilder() .startObject() .field("field1", "value1") .field("field2", "value2") @@ -128,8 +128,8 @@ public void testDynamicStrict() throws IOException { 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + () -> defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", "value1") .field("field2", (String) null) @@ -151,8 +151,8 @@ public void testDynamicFalseWithInnerObjectButDynamicSetOnRoot() throws IOExcept DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(jsonBuilder() .startObject().startObject("obj1") .field("field1", "value1") .field("field2", "value2") @@ -178,8 +178,8 @@ public void testDynamicStrictWithInnerObjectButDynamicSetOnRoot() throws IOExcep .parse("type", new CompressedXContent(mapping)); StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () -> - defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(jsonBuilder() + defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(jsonBuilder() .startObject().startObject("obj1") .field("field1", "value1") .field("field2", "value2") @@ -207,8 +207,8 @@ private Mapper parse(DocumentMapper mapper, DocumentMapperParser parser, XConten .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", - null, BytesReference.bytes(builder), builder.contentType()); + 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); assertEquals(XContentParser.Token.START_OBJECT, ctx.parser().nextToken()); @@ -561,7 +561,7 @@ public void testMixTemplateMultiFieldAndMappingReuse() throws Exception { XContentBuilder json = XContentFactory.jsonBuilder().startObject() .field("field", "foo") .endObject(); - SourceToParse source = SourceToParse.source("test", "_doc", "1", null, 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,8 +596,8 @@ private void doTestDefaultFloatingPointMappings(DocumentMapper mapper, XContentB .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", - null, source, builder.contentType())); + ParsedDocument parsedDocument = mapper.parse(new SourceToParse("index", "type", "id", + source, builder.contentType())); Mapping update = parsedDocument.dynamicMappingsUpdate(); assertNotNull(update); assertThat(((FieldMapper) update.root().getMapper("foo")).fieldType().typeName(), equalTo("float")); @@ -615,7 +615,7 @@ public void testNumericDetectionEnabled() throws Exception { 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", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("s_long", "100") @@ -642,7 +642,7 @@ public void testNumericDetectionDefault() throws Exception { 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", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("s_long", "100") @@ -691,7 +691,7 @@ public void testDateDetectionInheritsFormat() throws Exception { 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", null, 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 892e66f9fd14b..6b451b64db0d1 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 void testDynamicMappingDefault() throws IOException { .documentMapperWithAutoCreate("my-type").getDocumentMapper(); ParsedDocument parsedDoc = documentMapper.parse( - SourceToParse.source("my-index", "my-type", "1", null, 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 74f1fb571cc17..ff44dec81d962 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 void testMatchTypeOnly() throws Exception { 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", null, 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 void testSimple() throws Exception { 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", null, 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 void testSimpleWithXContentTraverse() throws Exception { 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", null, 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 e5ea8cdb21c18..e2f9f798a1441 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 void testExternalValues() throws Exception { .endObject().endObject()) )); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -146,7 +146,7 @@ public void testExternalValuesWithMultifield() throws Exception { .endObject() .endObject().endObject().endObject()))); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -213,7 +213,7 @@ public void testExternalValuesWithMultifieldTwoLevels() throws Exception { .endObject() .endObject().endObject().endObject()))); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", null, 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 b93e27c45ed05..d0d4a6b1d15b7 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java @@ -82,8 +82,8 @@ public void testInjectIntoDocDuringParsing() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("a", "100") .startObject("b") @@ -106,8 +106,8 @@ public void testExplicitEnabled() throws Exception { FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class); assertTrue(fieldNamesMapper.fieldType().isEnabled()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), @@ -125,8 +125,8 @@ public void testDisabled() throws Exception { FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class); assertFalse(fieldNamesMapper.fieldType().isEnabled()); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), 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 05d88a7ef8434..e67469bcd85ff 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 void testSimple() throws Exception { byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-data.json"); ParsedDocument parsedDoc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", null, 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 ac9ec7dea27eb..f5597ecb1f443 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java @@ -65,8 +65,8 @@ public void testGeoHashValue() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", stringEncode(1.3, 1.2)) .endObject()), @@ -82,8 +82,8 @@ public void testLatLonValuesStored() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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() .endObject()), @@ -99,8 +99,8 @@ public void testArrayLatLonValues() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") .startObject().field("lat", 1.2).field("lon", 1.3).endObject() @@ -121,8 +121,8 @@ public void testLatLonInOneValue() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3") .endObject()), @@ -139,8 +139,8 @@ public void testLatLonStringWithZValue() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3,10.0") .endObject()), @@ -157,8 +157,8 @@ public void testLatLonStringWithZValueException() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - SourceToParse source = SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + SourceToParse source = new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3,10.0") .endObject()), @@ -175,8 +175,8 @@ public void testLatLonInOneValueStored() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("point", "1.2,1.3") .endObject()), @@ -191,8 +191,8 @@ public void testLatLonInOneValueArray() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") .value("1.2,1.3") @@ -213,8 +213,8 @@ public void testLonLatArray() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() .endObject()), @@ -231,8 +231,8 @@ public void testLonLatArrayDynamic() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() .endObject()), @@ -248,8 +248,8 @@ public void testLonLatArrayStored() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point").value(1.3).value(1.2).endArray() .endObject()), @@ -268,8 +268,8 @@ public void testLonLatArrayArrayStored() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startArray("point") .startArray().value(1.3).value(1.2).endArray() @@ -381,8 +381,8 @@ public void testNullValue() throws Exception { Object nullValue = ((GeoPointFieldMapper) fieldMapper).fieldType().nullValue(); assertThat(nullValue, equalTo(new GeoPoint(1, 2))); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("location") .endObject()), @@ -391,8 +391,8 @@ public void testNullValue() throws Exception { assertThat(doc.rootDoc().getField("location"), notNullValue()); BytesRef defaultValue = doc.rootDoc().getField("location").binaryValue(); - doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1, 2") .endObject()), @@ -400,8 +400,8 @@ public void testNullValue() throws Exception { // 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "3, 4") .endObject()), @@ -422,8 +422,8 @@ public void testInvalidGeohashIgnored() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1234.333") .endObject()), @@ -445,8 +445,8 @@ public void testInvalidGeohashNotIgnored() throws Exception { .parse("type", new CompressedXContent(mapping)); MapperParsingException ex = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + () -> defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("location", "1234.333") .endObject()), @@ -469,58 +469,58 @@ public void testInvalidGeopointValuesIgnored() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + 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 651ea361ccd43..f015dee1f8931 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 void testIncludeInObjectNotAllowed() throws Exception { .parse("type", new CompressedXContent(mapping)); try { - docMapper.parse(SourceToParse.source("test", "type", "1", null, 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,8 +62,8 @@ public void testDefaults() throws IOException { 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", - null, new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(new SourceToParse("index", "type", "id", + new BytesArray("{}"), XContentType.JSON)); IndexableField[] fields = document.rootDoc().getFields(IdFieldMapper.NAME); assertEquals(1, fields.length); assertEquals(IndexOptions.DOCS, fields[0].fieldType().indexOptions()); 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 8aa6f86d710eb..7fd867f9b3425 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java @@ -47,8 +47,8 @@ public void testDefaultDisabledIndexMapper() throws Exception { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), 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 b7f33e0fbb534..6396b3988bc7d 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -97,7 +97,7 @@ public void testNotIndexed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -119,7 +119,7 @@ public void testNoDocValues() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -142,7 +142,7 @@ public void testStore() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "::1") @@ -170,7 +170,7 @@ public void testIgnoreMalformed() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -185,7 +185,7 @@ public void testIgnoreMalformed() throws Exception { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", ":1") @@ -210,7 +210,7 @@ public void testNullValue() throws IOException { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -231,7 +231,7 @@ public void testNullValue() throws IOException { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 9c2db006a155c..9b126da4c2bc9 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 void testStoreCidr() throws Exception { 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", null, 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 073799191fb00..fba695ba86cac 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 void testMergeMultiField() throws Exception { BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); Document doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", null, 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 void testMergeMultiField() throws Exception { assertThat(mapperService.fullName("name.not_indexed2"), nullValue()); assertThat(mapperService.fullName("name.not_indexed3"), nullValue()); - doc = mapperService.documentMapper().parse(SourceToParse.source("test", "person", "1", null, 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 void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception { BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); Document doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", null, 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 void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception { assertThat(mapperService.fullName("name.not_indexed3"), nullValue()); doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", null, 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 18d8bd9405853..d7f8d48fc5cf3 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 void testDefaults() throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -147,7 +147,7 @@ public void testIgnoreAbove() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "elk") @@ -157,7 +157,7 @@ public void testIgnoreAbove() throws IOException { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "elasticsearch") @@ -176,7 +176,7 @@ public void testNullValue() throws IOException { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -192,7 +192,7 @@ public void testNullValue() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .endObject()), @@ -201,7 +201,7 @@ public void testNullValue() throws IOException { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -222,7 +222,7 @@ public void testEnableStore() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -243,7 +243,7 @@ public void testDisableIndex() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -265,7 +265,7 @@ public void testDisableDocValues() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -287,7 +287,7 @@ public void testIndexOptions() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -333,7 +333,7 @@ public void testEnableNorms() throws IOException { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -358,7 +358,7 @@ public void testNormalizer() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 b08a1eae04d85..6bd0b608f3f0e 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 @@ private void testMultiField(String mapping) throws Exception { BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json")); Document doc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", null, 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 void testBuildThenParse() throws Exception { BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", null, 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 2a58bedc6bb5a..d3f41589fb1fd 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 void testEmptyNested() throws Exception { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -73,7 +73,7 @@ public void testEmptyNested() throws Exception { assertThat(doc.docs().size(), equalTo(1)); - doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -96,7 +96,7 @@ public void testSingleNested() throws Exception { ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1"); assertThat(nested1Mapper.nested().isNested(), equalTo(true)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -112,7 +112,7 @@ public void testSingleNested() throws Exception { assertThat(doc.docs().get(1).get("field"), equalTo("value")); - doc = docMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -154,8 +154,8 @@ public void testMultiNested() throws Exception { assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false)); assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -215,8 +215,8 @@ public void testMultiObjectAndNested1() throws Exception { assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true)); assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -278,8 +278,8 @@ public void testMultiObjectAndNested2() throws Exception { assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true)); assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -339,8 +339,8 @@ public void testMultiRootAndNested1() throws Exception { assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false)); assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(true)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -398,8 +398,8 @@ public void testMultipleLevelsIncludeRoot1() throws Exception { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().startArray("nested1") .startObject().startArray("nested2").startObject().field("foo", "bar") .endObject().endArray().endObject().endArray() @@ -432,8 +432,8 @@ public void testMultipleLevelsIncludeRoot2() throws Exception { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject().startArray("nested1") .startObject().startArray("nested2") .startObject().startArray("nested3").startObject().field("foo", "bar") @@ -460,8 +460,8 @@ public void testNestedArrayStrict() throws Exception { assertThat(nested1Mapper.nested().isNested(), equalTo(true)); assertThat(nested1Mapper.dynamic(), equalTo(Dynamic.STRICT)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") @@ -568,8 +568,8 @@ public void testLimitNestedDocsDefaultSettings() throws Exception{ docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = SourceToParse.source("test1", "type", "1", - null, BytesReference.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "type", "1", + BytesReference.bytes(docBuilder), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source1)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" + defaultMaxNoNestedDocs @@ -601,8 +601,8 @@ public void testLimitNestedDocs() throws Exception{ docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = SourceToParse.source("test1", "type", "1", - null, BytesReference.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "type", "1", + BytesReference.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -619,8 +619,8 @@ public void testLimitNestedDocs() throws Exception{ docBuilder2.endArray(); } docBuilder2.endObject(); - SourceToParse source2 = SourceToParse.source("test1", "type", "2", - null, BytesReference.bytes(docBuilder2), XContentType.JSON); + SourceToParse source2 = new SourceToParse("test1", "type", "2", + BytesReference.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" + maxNoNestedDocs @@ -657,8 +657,8 @@ public void testLimitNestedDocsMultipleNestedFields() throws Exception{ docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = SourceToParse.source("test1", "type", "1", - null, BytesReference.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "type", "1", + BytesReference.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -680,8 +680,8 @@ public void testLimitNestedDocsMultipleNestedFields() throws Exception{ } docBuilder2.endObject(); - SourceToParse source2 = SourceToParse.source("test1", "type", "2", - null, BytesReference.bytes(docBuilder2), XContentType.JSON); + SourceToParse source2 = new SourceToParse("test1", "type", "2", + BytesReference.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" + maxNoNestedDocs @@ -714,8 +714,8 @@ public void testReorderParentBWC() throws IOException { ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1"); assertThat(nested1Mapper.nested().isNested(), equalTo(true)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .startArray("nested1") 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 27b1d803d3b6b..85922fccff80a 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java @@ -39,8 +39,8 @@ public void testNullValueObject() throws IOException { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("obj1").endObject() .field("value1", "test1") @@ -49,8 +49,8 @@ public void testNullValueObject() throws IOException { assertThat(doc.rootDoc().get("value1"), equalTo("test1")); - doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .nullField("obj1") .field("value1", "test1") @@ -59,8 +59,8 @@ public void testNullValueObject() throws IOException { assertThat(doc.rootDoc().get("value1"), equalTo("test1")); - doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder() + doc = defaultMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("obj1").field("field", "value").endObject() .field("value1", "test1") 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 c72f1707c2319..ba7f5d846840a 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 void doTestDefaults(String type) throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -84,7 +84,7 @@ public void doTestNotIndexed(String type) throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -107,7 +107,7 @@ public void doTestNoDocValues(String type) throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -131,7 +131,7 @@ public void doTestStore(String type) throws Exception { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", 123) @@ -160,7 +160,7 @@ public void doTestCoerce(String type) throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -183,7 +183,7 @@ public void doTestCoerce(String type) throws IOException { assertEquals(mapping, mapper2.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ThrowingRunnable runnable = () -> mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "123") @@ -203,7 +203,7 @@ protected void doTestDecimalCoerce(String type) throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "7.89") @@ -230,7 +230,7 @@ private void doTestIgnoreMalformed(String type) throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "a") @@ -246,7 +246,7 @@ private void doTestIgnoreMalformed(String type) throws IOException { DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "a") @@ -308,7 +308,7 @@ protected void doTestNullValue(String type) throws IOException { DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -335,7 +335,7 @@ protected void doTestNullValue(String type) throws IOException { mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -422,7 +422,7 @@ public void testOutOfRangeValues() throws IOException { } private void parseRequest(NumberType type, BytesReference content) throws IOException { - createDocumentMapper(type).parse(SourceToParse.source("test", "type", "1", null, 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 21a4cf8ab721c..db3feee39e04d 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 void testDifferentInnerObjectTokenFailure() throws Exception { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { - defaultMapper.parse(SourceToParse.source("test", "type", "1", null, 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 20e96e0faf5fe..31cfd5e82ee31 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 void testSimple() throws Exception { byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json"); ParsedDocument parsedDoc = mapperService.documentMapper().parse( - SourceToParse.source("test", "person", "1", null, 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 b16730a586e53..fcb78f66add5e 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 void doTestDefaults(String type) throws Exception { 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", null, 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 @@ protected void doTestNotIndexed(String type) throws Exception { 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", null, 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 @@ protected void doTestNoDocValues(String type) throws Exception { 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", null, 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 @@ protected void doTestStore(String type) throws Exception { 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", null, 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 void doTestCoerce(String type) throws IOException { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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,8 +267,8 @@ public void doTestCoerce(String type) throws IOException { assertEquals(Strings.toString(mapping), mapper2.mappingSource().toString()); ThrowingRunnable runnable = () -> mapper2 - .parse(SourceToParse.source( - "test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("field") + .parse(new SourceToParse( + "test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("field") .field(getFromField(), "5.2").field(getToField(), "10").endObject().endObject()), XContentType.JSON)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); @@ -287,8 +287,7 @@ protected void doTestDecimalCoerce(String type) throws IOException { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); - ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", null, - 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") @@ -297,8 +296,7 @@ protected void doTestDecimalCoerce(String type) throws IOException { .endObject()), XContentType.JSON)); - ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", null, - 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") @@ -326,7 +324,7 @@ protected void doTestNullValue(String type) throws IOException { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); // test null value for min and max - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .nullField(getFromField()) @@ -341,7 +339,7 @@ protected void doTestNullValue(String type) throws IOException { assertThat(storedField.stringValue(), containsString(expected)); // test null max value - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference.bytes(XContentFactory.jsonBuilder() + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() .startObject("field") .field(getFromField(), getFrom(type)) @@ -369,7 +367,7 @@ protected void doTestNullValue(String type) throws IOException { assertThat(storedField.stringValue(), containsString(strVal)); // test null range - doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .nullField("field") @@ -396,7 +394,7 @@ public void doTestNoBounds(String type) throws IOException { assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); // test no bounds specified - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 7351e555ccca0..3da00e3f787c9 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 void testRoutingMapper() throws Exception { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", "routing_value", BytesReference + ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "value") .endObject()), - XContentType.JSON)); + XContentType.JSON, "routing_value")); assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value")); assertThat(doc.rootDoc().get("field"), equalTo("value")); @@ -54,7 +54,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { .parse("type", new CompressedXContent(mapping)); try { - docMapper.parse(SourceToParse.source("test", "type", "1", null, 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 d24b98d8cb709..a8db41e677b95 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java @@ -54,8 +54,8 @@ public void testNoFormat() throws Exception { DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.jsonBuilder().startObject() .field("field", "value") .endObject()), XContentType.JSON)); @@ -63,8 +63,8 @@ public void testNoFormat() throws Exception { 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", - null, BytesReference.bytes(XContentFactory.smileBuilder().startObject() + doc = documentMapper.parse(new SourceToParse("test", "type", "1", + BytesReference.bytes(XContentFactory.smileBuilder().startObject() .field("field", "value") .endObject()), XContentType.SMILE)); @@ -80,8 +80,8 @@ public void testIncludes() throws Exception { DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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() .endObject()), @@ -104,8 +104,8 @@ public void testExcludes() throws Exception { DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser() .parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", - null, BytesReference.bytes(XContentFactory.jsonBuilder().startObject() + 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() .endObject()), @@ -216,8 +216,8 @@ public void testSourceObjectContainsExtraTokens() throws Exception { .parse("type", new CompressedXContent(mapping)); try { - documentMapper.parse(SourceToParse.source("test", "type", "1", - null, new BytesArray("{}}"), XContentType.JSON)); // extra end object (invalid JSON) + documentMapper.parse(new SourceToParse("test", "type", "1", + new BytesArray("{}}"), XContentType.JSON)); // extra end object (invalid JSON) fail("Expected parse exception"); } catch (MapperParsingException e) { assertNotNull(e.getRootCause()); 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 7658ec2cc5a06..1b279f4d26866 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 void testBytesAndNumericRepresentation() throws Exception { 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", null, 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 c8278017ac1d4..acd6c9ee6f80b 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 void testDefaults() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -135,7 +135,7 @@ public void testEnableStore() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -156,7 +156,7 @@ public void testDisableIndex() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -179,7 +179,7 @@ public void testDisableNorms() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field", "1234") @@ -210,7 +210,7 @@ public void testIndexOptions() throws IOException { for (String option : supportedOptions.keySet()) { jsonDoc.field(option, "1234"); } - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testDefaultPositionIncrementGap() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[] {"a", "b"}) @@ -274,7 +274,7 @@ public void testPositionIncrementGap() throws IOException { assertEquals(mapping, mapper.mappingSource().toString()); - SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", null, BytesReference + SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .array("field", new String[]{"a", "b"}) @@ -433,7 +433,7 @@ public void testTermVectors() throws IOException { DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping)); - ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", null, BytesReference + ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference .bytes(XContentFactory.jsonBuilder() .startObject() .field("field1", "1234") @@ -765,7 +765,7 @@ public void testFastPhraseMapping() throws IOException { new Term("synfield._index_phrase", "motor dog")}) .build())); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 void testIndexPrefixMapping() throws IOException { assertThat(mapper.mappers().getMapper("field._index_prefix").toString(), containsString("prefixChars=2:10")); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", null, 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 e412adc893d85..c763040d01d60 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 void testDocValuesSingleType() throws Exception { 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", null, 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 void testDefaults() throws IOException { 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", null, 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 8700799015e36..6f38822092aea 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 void testRecoveryToReplicaThatReceivedExtraDocument() throws Exception { 1, randomNonNegativeLong(), false, - SourceToParse.source("index", "type", "replica", null, 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 void testRecoveryToReplicaThatReceivedExtraDocument() throws Exception { promotedReplica.applyIndexOperationOnPrimary( Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("index", "type", "primary", null, 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 264cc9f8a4971..475caf06e30a8 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 void testMaybeFlush() throws Exception { .setSource("{}", XContentType.JSON).setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get(); assertFalse(shard.shouldPeriodicallyFlush()); shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("test", "test", "1", null, 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 void testMaybeRollTranslogGeneration() throws Exception { 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", null, 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 d274e76629b71..4745904a55467 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 void testRecoverFromStoreWithOutOfOrderDelete() throws IOException { 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", null, 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", null, 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", null, 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", null, new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(shard.shardId().getIndexName(), "_doc", "id-5", new BytesArray("{}"), XContentType.JSON)); final int translogOps; if (randomBoolean()) { @@ -1912,8 +1912,8 @@ public void testRecoverFromStoreWithNoOps() throws IOException { // 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", - null, new BytesArray("{}"), XContentType.JSON); + 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 void testRecoverFromStoreRemoveStaleOperations() throws Exception { 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", null, 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", null, 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 void testRecoverFromStoreRemoveStaleOperations() throws Exception { shard.getEngine().rollTranslogGeneration(); shard.markSeqNoAsNoop(1, "test"); shard.applyIndexOperationOnReplica(2, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(indexName, "_doc", "doc-2", null, 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,8 +3037,8 @@ private Result indexOnReplicaWithGaps( 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, - null, new BytesArray("{}"), XContentType.JSON); + SourceToParse sourceToParse = new SourceToParse(indexShard.shardId().getIndexName(), "_doc", id, + new BytesArray("{}"), XContentType.JSON); indexShard.applyIndexOperationOnReplica(i, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); if (!gap && i == localCheckpoint + 1) { 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 f75234bf73d44..d074ef3375833 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java @@ -80,8 +80,7 @@ public void testSyncerSendsOffCorrectDocuments() throws Exception { 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), null, - 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); } @@ -151,8 +150,7 @@ public void testSyncerOnClosingShard() throws Exception { 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), null, - 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 4e951fccae34f..48061b11d58c7 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 void testRecoveryWithOutOfOrderDeleteWithTranslog() throws Exception { 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", null, 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", null, 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", null, 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", null, new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON)); final int translogOps; if (randomBoolean()) { @@ -196,19 +196,19 @@ public void testRecoveryWithOutOfOrderDeleteWithSoftDeletes() throws Exception { 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", null, 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", null, 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", null, 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", null, new BytesArray("{}"), XContentType.JSON)); + new SourceToParse(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON)); if (randomBoolean()) { if (randomBoolean()) { @@ -312,7 +312,7 @@ public void testPeerRecoverySendSafeCommitInFileBased() throws Exception { 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), null, 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 cbc73644cf01b..812735092ba44 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 void testIndexingWithNoContexts() throws Exception { 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", null, BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -116,7 +116,7 @@ public void testIndexingWithSimpleContexts() throws Exception { 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", null, BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -150,7 +150,7 @@ public void testIndexingWithSimpleNumberContexts() throws Exception { 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", null, BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -184,7 +184,7 @@ public void testIndexingWithSimpleBooleanContexts() throws Exception { 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", null, BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startArray("completion") @@ -231,7 +231,7 @@ public void testIndexingWithSimpleNULLContexts() throws Exception { .endObject(); Exception e = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testIndexingWithContextList() throws Exception { 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", null, BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startObject("completion") @@ -284,7 +284,7 @@ public void testIndexingWithMixedTypeContextList() throws Exception { 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", null, BytesReference + ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference .bytes(jsonBuilder() .startObject() .startObject("completion") @@ -327,7 +327,7 @@ public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception { .endObject(); Exception e = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 void testIndexingWithMultipleContexts() throws Exception { .endObject() .endArray() .endObject(); - ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", null, 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 4f110682be128..85e97d16e3b4f 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,8 +63,8 @@ public void testIndexingWithNoContexts() throws Exception { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(jsonBuilder() + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(jsonBuilder() .startObject() .startArray("completion") .startObject() @@ -102,8 +102,8 @@ public void testIndexingWithSimpleContexts() throws Exception { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(jsonBuilder() + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(jsonBuilder() .startObject() .startArray("completion") .startObject() @@ -138,8 +138,8 @@ public void testIndexingWithContextList() throws Exception { MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fullName("completion"); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(jsonBuilder() + ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1", + BytesReference.bytes(jsonBuilder() .startObject() .startObject("completion") .array("input", "suggestion5", "suggestion6", "suggestion7") @@ -195,8 +195,8 @@ public void testIndexingWithMultipleContexts() throws Exception { .endObject() .endArray() .endObject(); - ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1", - null, BytesReference.bytes(builder), XContentType.JSON)); + 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 925e7c935ef1f..f07c5e1b21f22 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 static CheckedBiFunction ne source.endObject(); } source.endObject(); - return nestedMapper.parse(SourceToParse.source("test", "type", docId, null, 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 5a9e0ef1eaebd..7090419e9f23d 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.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 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,8 +122,8 @@ private Engine.Operation convertToEngineOp(Translog.Operation operation, Engine. 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.routing(), index.source(), - XContentHelper.xContentType(index.source())), 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 c7da5bf9f8160..84e88b6accc5b 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 @@ protected Engine.IndexResult indexDoc(IndexShard shard, String type, String id, 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, routing, - new BytesArray(source), xContentType); + 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 d60f92995fbfc..8d3c0c3b472aa 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,14 +39,14 @@ public void testDoNotFillGaps() throws Exception { 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, - null, new BytesArray("{}"), XContentType.JSON); + 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", - null, new BytesArray("{}"), XContentType.JSON); + SourceToParse sourceToParse = new SourceToParse(indexShard.shardId().getIndexName(), "_doc", "9", + new BytesArray("{}"), XContentType.JSON); indexShard.applyIndexOperationOnReplica(seqNo, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse); // promote the replica to primary: 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 f564878d6936a..28244b523e129 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.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.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 { @@ -294,8 +293,8 @@ public IndexShard reindex(DirectoryReader reader, MappingMetaData mapping) throw 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(), rootFieldsVisitor.routing(), source, XContentHelper.xContentType(source)), - SequenceNumbers.UNASSIGNED_SEQ_NO, 0, 1, false); + 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());