Make SourceToParse immutable (#36971)

Today the routing of a SourceToParse is assigned in a separate step
after the object is created. We can easily forget to set the routing.
With this commit, the routing must be provided in the constructor of
SourceToParse.

Relates #36921
This commit is contained in:
Nhat Nguyen 2018-12-24 14:06:50 -05:00 committed by GitHub
parent 531ae8b3ab
commit 7580d9d925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 433 additions and 444 deletions

View File

@ -582,7 +582,7 @@ public class PainlessExecuteAction extends Action<PainlessExecuteAction.Response
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 = new SourceToParse(index, type, "_id", document, xContentType);
ParsedDocument parsedDocument = indexService.mapperService().documentMapper().parse(sourceToParse);
indexWriter.addDocuments(parsedDocument.docs());
try (IndexReader indexReader = DirectoryReader.open(indexWriter)) {

View File

@ -58,7 +58,7 @@ public class DenseVectorFieldMapperTests extends ESSingleNodeTestCase {
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(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()

View File

@ -72,7 +72,7 @@ public class FeatureFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 10)
@ -84,7 +84,7 @@ public class FeatureFieldMapperTests extends ESSingleNodeTestCase {
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(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 12)
@ -108,7 +108,7 @@ public class FeatureFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 10)
@ -120,7 +120,7 @@ public class FeatureFieldMapperTests extends ESSingleNodeTestCase {
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(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 12)
@ -145,7 +145,7 @@ public class FeatureFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
MapperParsingException e = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
() -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", Arrays.asList(10, 20))
@ -155,7 +155,7 @@ public class FeatureFieldMapperTests extends ESSingleNodeTestCase {
e.getCause().getMessage());
e = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
() -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("foo")

View File

@ -61,7 +61,7 @@ public class FeatureVectorFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
@ -95,7 +95,7 @@ public class FeatureVectorFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
MapperParsingException e = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
() -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
@ -107,7 +107,7 @@ public class FeatureVectorFieldMapperTests extends ESSingleNodeTestCase {
"START_ARRAY", e.getCause().getMessage());
e = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
() -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("foo")

View File

@ -65,7 +65,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 123)
@ -115,7 +115,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 123)
@ -139,7 +139,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 123)
@ -163,7 +163,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 123)
@ -192,7 +192,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "123")
@ -216,7 +216,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper2.mappingSource().toString());
ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference
ThrowingRunnable runnable = () -> mapper2.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "123")
@ -245,7 +245,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", value)
@ -261,7 +261,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", value)
@ -286,7 +286,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -308,7 +308,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")

View File

@ -65,7 +65,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase {
public void testDefaults() throws Exception {
int[] indexedDims = {65535, 50, 2};
float[] indexedValues = {0.5f, 1800f, -34567.11f};
ParsedDocument doc1 = mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference
ParsedDocument doc1 = mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("my-sparse-vector")
@ -103,7 +103,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase {
public void testErrors() {
// 1. test for an error on negative dimension
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference
mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("my-sparse-vector")
@ -118,7 +118,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase {
// 2. test for an error on a dimension greater than MAX_DIMS_NUMBER
e = expectThrows(MapperParsingException.class, () -> {
mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference
mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("my-sparse-vector")
@ -133,7 +133,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase {
// 3. test for an error on a wrong formatted dimension
e = expectThrows(MapperParsingException.class, () -> {
mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference
mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("my-sparse-vector")
@ -148,7 +148,7 @@ public class SparseVectorFieldMapperTests extends ESSingleNodeTestCase {
// 4. test for an error on a wrong format for the map of dims to values
e = expectThrows(MapperParsingException.class, () -> {
mapper.parse(SourceToParse.source("test-index", "_doc", "1", BytesReference
mapper.parse(new SourceToParse("test-index", "_doc", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("my-sparse-vector")

View File

@ -192,7 +192,7 @@ public class TokenCountFieldMapperTests extends ESSingleNodeTestCase {
.field("test", fieldValue)
.endObject());
return SourceToParse.source("test", "person", "1", request, XContentType.JSON);
return new SourceToParse("test", "person", "1", request, XContentType.JSON);
}
private ParseContext.Document parseDocument(DocumentMapper mapper, SourceToParse request) {

View File

@ -63,12 +63,12 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase {
assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService()));
// Doc without join
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "0",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON));
assertNull(doc.rootDoc().getBinaryValue("join_field"));
// Doc parent
doc = docMapper.parse(SourceToParse.source("test", "type", "1",
doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field("join_field", "parent")
.endObject()), XContentType.JSON));
@ -76,19 +76,19 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase {
assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Doc child
doc = docMapper.parse(SourceToParse.source("test", "type", "2",
doc = docMapper.parse(new SourceToParse("test", "type", "2",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.startObject("join_field")
.field("name", "child")
.field("parent", "1")
.endObject()
.endObject()), XContentType.JSON).routing("1"));
.endObject()), XContentType.JSON, "1"));
assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString());
assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Unkwnown join name
MapperException exc = expectThrows(MapperParsingException.class,
() -> docMapper.parse(SourceToParse.source("test", "type", "1",
() -> docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field("join_field", "unknown")
.endObject()), XContentType.JSON)));
@ -109,22 +109,22 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase {
IndexService service = createIndex("test");
DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping),
MapperService.MergeReason.MAPPING_UPDATE);
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "2",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "2",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.startObject("join_field")
.field("name", "child")
.field("parent", 1)
.endObject()
.endObject()), XContentType.JSON).routing("1"));
.endObject()), XContentType.JSON, "1"));
assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString());
assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
doc = docMapper.parse(SourceToParse.source("test", "type", "2",
doc = docMapper.parse(new SourceToParse("test", "type", "2",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.startObject("join_field")
.field("name", "child")
.field("parent", 1.0)
.endObject()
.endObject()), XContentType.JSON).routing("1"));
.endObject()), XContentType.JSON, "1"));
assertEquals("1.0", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString());
assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
}
@ -147,12 +147,12 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase {
assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService()));
// Doc without join
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "0",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON));
assertNull(doc.rootDoc().getBinaryValue("join_field"));
// Doc parent
doc = docMapper.parse(SourceToParse.source("test", "type", "1",
doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("join_field", "parent")
@ -161,28 +161,28 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase {
assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Doc child
doc = docMapper.parse(SourceToParse.source("test", "type", "2",
doc = docMapper.parse(new SourceToParse("test", "type", "2",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.startObject("join_field")
.field("name", "child")
.field("parent", "1")
.endObject()
.endObject()), XContentType.JSON).routing("1"));
.endObject()), XContentType.JSON, "1"));
assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString());
assertEquals("2", doc.rootDoc().getBinaryValue("join_field#child").utf8ToString());
assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Doc child missing parent
MapperException exc = expectThrows(MapperParsingException.class,
() -> docMapper.parse(SourceToParse.source("test", "type", "2",
() -> docMapper.parse(new SourceToParse("test", "type", "2",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field("join_field", "child")
.endObject()), XContentType.JSON).routing("1")));
.endObject()), XContentType.JSON, "1")));
assertThat(exc.getRootCause().getMessage(), containsString("[parent] is missing for join field [join_field]"));
// Doc child missing routing
exc = expectThrows(MapperParsingException.class,
() -> docMapper.parse(SourceToParse.source("test", "type", "2",
() -> docMapper.parse(new SourceToParse("test", "type", "2",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.startObject("join_field")
.field("name", "child")
@ -192,19 +192,19 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase {
assertThat(exc.getRootCause().getMessage(), containsString("[routing] is missing for join field [join_field]"));
// Doc grand_child
doc = docMapper.parse(SourceToParse.source("test", "type", "3",
doc = docMapper.parse(new SourceToParse("test", "type", "3",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.startObject("join_field")
.field("name", "grand_child")
.field("parent", "2")
.endObject()
.endObject()), XContentType.JSON).routing("1"));
.endObject()), XContentType.JSON, "1"));
assertEquals("2", doc.rootDoc().getBinaryValue("join_field#child").utf8ToString());
assertEquals("grand_child", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Unkwnown join name
exc = expectThrows(MapperParsingException.class,
() -> docMapper.parse(SourceToParse.source("test", "type", "1",
() -> docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field("join_field", "unknown")
.endObject()), XContentType.JSON)));

View File

@ -71,6 +71,7 @@ import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryRewriteContext;
@ -89,7 +90,6 @@ import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
import static org.elasticsearch.index.mapper.SourceToParse.source;
import static org.elasticsearch.percolator.PercolatorFieldMapper.parseQuery;
public class PercolateQueryBuilder extends AbstractQueryBuilder<PercolateQueryBuilder> {
@ -585,7 +585,7 @@ public class PercolateQueryBuilder extends AbstractQueryBuilder<PercolateQueryBu
}
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(new SourceToParse(context.index().getName(), type, "_temp_id", document, documentXContentType)));
}
FieldNameAnalyzer fieldNameAnalyzer = (FieldNameAnalyzer) docMapper.mappers().indexAnalyzer();

View File

@ -479,7 +479,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
public void testPercolatorFieldMapper() throws Exception {
addQueryFieldMappings();
QueryBuilder queryBuilder = termQuery("field", "value");
ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1",
ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory
.jsonBuilder()
.startObject()
@ -498,7 +498,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
// 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(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory
.jsonBuilder()
.startObject()
.field(fieldName, queryBuilder)
@ -524,7 +524,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
// (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",
ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field(fieldName, query)
.endObject()),
@ -538,7 +538,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
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",
ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory
.jsonBuilder()
.startObject()
@ -559,7 +559,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
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(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory
.jsonBuilder()
.startObject()
.field(fieldName, termQuery("unmapped_field", "value"))
@ -573,7 +573,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
public void testPercolatorFieldMapper_noQuery() throws Exception {
addQueryFieldMappings();
ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", BytesReference
ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference
.bytes(XContentFactory
.jsonBuilder()
.startObject()
@ -582,7 +582,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
assertThat(doc.rootDoc().getFields(fieldType.queryBuilderField.name()).length, equalTo(0));
try {
mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1", BytesReference.bytes(XContentFactory
mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory
.jsonBuilder()
.startObject()
.nullField(fieldName)
@ -619,7 +619,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE);
QueryBuilder queryBuilder = matchQuery("field", "value");
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
ParsedDocument doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1",
BytesReference.bytes(jsonBuilder().startObject()
.field("query_field1", queryBuilder)
.field("query_field2", queryBuilder)
@ -650,7 +650,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE);
QueryBuilder queryBuilder = matchQuery("field", "value");
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
ParsedDocument doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1",
BytesReference.bytes(jsonBuilder().startObject().startObject("object_field")
.field("query_field", queryBuilder)
.endObject().endObject()),
@ -659,7 +659,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
BytesRef queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1",
BytesReference.bytes(jsonBuilder().startObject()
.startArray("object_field")
.startObject().field("query_field", queryBuilder).endObject()
@ -671,7 +671,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1",
BytesReference.bytes(jsonBuilder().startObject()
.startArray("object_field")
.startObject().field("query_field", queryBuilder).endObject()
@ -756,7 +756,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
query.endObject();
query.endObject();
ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1",
ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType())
.endObject()),
@ -794,7 +794,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
query.endObject();
query.endObject();
doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1",
doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType())
.endObject()),
@ -880,7 +880,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
QueryBuilder qb = boolQuery()
.must(boolQuery().must(termQuery("field", "value1")).must(termQuery("field", "value2")))
.must(boolQuery().must(termQuery("field", "value2")).must(termQuery("field", "value3")));
ParsedDocument doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1",
ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field(fieldName, qb)
.endObject()),
@ -902,7 +902,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
.must(boolQuery().must(termQuery("field", "value2")).must(termQuery("field", "value3")))
.must(boolQuery().must(termQuery("field", "value3")).must(termQuery("field", "value4")))
.must(boolQuery().should(termQuery("field", "value4")).should(termQuery("field", "value5")));
doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1",
doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field(fieldName, qb)
.endObject()),
@ -927,7 +927,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
.should(boolQuery().should(termQuery("field", "value2")).should(termQuery("field", "value3")))
.should(boolQuery().should(termQuery("field", "value3")).should(termQuery("field", "value4")))
.should(boolQuery().should(termQuery("field", "value4")).should(termQuery("field", "value5")));
doc = mapperService.documentMapper("doc").parse(SourceToParse.source("test", "doc", "1",
doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field(fieldName, qb)
.endObject()),

View File

@ -72,7 +72,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -112,7 +112,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -129,7 +129,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.endObject()),
@ -138,7 +138,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
IndexableField[] fields = doc.rootDoc().getFields("field");
assertEquals(0, fields.length);
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -164,7 +164,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -186,7 +186,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -209,7 +209,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -230,7 +230,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", Arrays.asList("1234", "5678"))
@ -293,7 +293,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -326,7 +326,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -350,7 +350,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "I WİLL USE TURKİSH CASING")

View File

@ -116,7 +116,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
// Use example of typed and untyped annotations
String annotatedText = "He paid [Stormy Daniels](Stephanie+Clifford&Payee) hush money";
SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference
SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", annotatedText)
@ -171,7 +171,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE);
String annotatedText = "foo [bar](MissingEndBracket baz";
SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference
SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", annotatedText)
@ -260,7 +260,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -292,7 +292,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -316,7 +316,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -347,7 +347,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
for (String option : supportedOptions.keySet()) {
jsonDoc.field(option, "1234");
}
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(jsonDoc.endObject()),
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(jsonDoc.endObject()),
XContentType.JSON));
for (Map.Entry<String, IndexOptions> entry : supportedOptions.entrySet()) {
@ -369,7 +369,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference
SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("field", new String[] {"a", "b"})
@ -411,7 +411,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference
SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("field", new String[]{"a", "b"})
@ -570,7 +570,7 @@ public class AnnotatedTextFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field1", "1234")

View File

@ -78,7 +78,7 @@ public class Murmur3FieldMapperTests extends ESSingleNodeTestCase {
.field("type", "murmur3")
.endObject().endObject().endObject().endObject());
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument parsedDoc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument parsedDoc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
.endObject()),

View File

@ -57,7 +57,7 @@ public class SizeMappingTests extends ESSingleNodeTestCase {
.startObject()
.field("field", "value")
.endObject());
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON));
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON));
boolean stored = false;
boolean points = false;
@ -78,7 +78,7 @@ public class SizeMappingTests extends ESSingleNodeTestCase {
.startObject()
.field("field", "value")
.endObject());
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON));
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON));
assertThat(doc.rootDoc().getField("_size"), nullValue());
}
@ -92,7 +92,7 @@ public class SizeMappingTests extends ESSingleNodeTestCase {
.startObject()
.field("field", "value")
.endObject());
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON));
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON));
assertThat(doc.rootDoc().getField("_size"), nullValue());
}

View File

@ -420,10 +420,8 @@ public class TransportShardBulkAction extends TransportWriteAction<BulkShardRequ
case INDEX:
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());
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;
@ -457,8 +455,7 @@ public class TransportShardBulkAction extends TransportWriteAction<BulkShardRequ
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());
new SourceToParse(request.index(), request.type(), request.id(), request.source(), request.getContentType(), request.routing());
executeOnPrimaryWhileHandlingMappingUpdates(context,
() ->
primary.applyIndexOperationOnPrimary(request.version(), request.versionType(), sourceToParse,

View File

@ -265,13 +265,13 @@ public class DocumentMapper implements ToXContentFragment {
}
public ParsedDocument createDeleteTombstoneDoc(String index, String type, String id) throws MapperParsingException {
final SourceToParse emptySource = SourceToParse.source(index, type, id, new BytesArray("{}"), XContentType.JSON);
final SourceToParse emptySource = new SourceToParse(index, type, id, new BytesArray("{}"), XContentType.JSON);
return documentParser.parseDocument(emptySource, deleteTombstoneMetadataFieldMappers).toTombstone();
}
public ParsedDocument createNoopTombstoneDoc(String index, String reason) throws MapperParsingException {
final String id = ""; // _id won't be used.
final SourceToParse sourceToParse = SourceToParse.source(index, type, id, new BytesArray("{}"), XContentType.JSON);
final SourceToParse sourceToParse = new SourceToParse(index, type, id, new BytesArray("{}"), XContentType.JSON);
final ParsedDocument parsedDoc = documentParser.parseDocument(sourceToParse, noopTombstoneMetadataFieldMappers).toTombstone();
// Store the reason of a noop as a raw string in the _source field
final BytesRef byteRef = new BytesRef(reason);

View File

@ -21,17 +21,13 @@ package org.elasticsearch.index.mapper;
import java.util.Objects;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentType;
public class SourceToParse {
public static SourceToParse source(String index, String type, String id, BytesReference source,
XContentType contentType) {
return new SourceToParse(index, type, id, source, contentType);
}
private final BytesReference source;
private final String index;
@ -40,11 +36,11 @@ public class SourceToParse {
private final String id;
private String routing;
private final @Nullable String routing;
private XContentType xContentType;
private final XContentType xContentType;
private SourceToParse(String index, String type, String id, BytesReference source, XContentType xContentType) {
public SourceToParse(String index, String type, String id, BytesReference source, XContentType xContentType, @Nullable String routing) {
this.index = Objects.requireNonNull(index);
this.type = Objects.requireNonNull(type);
this.id = Objects.requireNonNull(id);
@ -52,6 +48,11 @@ public class SourceToParse {
// so, we might as well do it here, and improve the performance of working with direct byte arrays
this.source = new BytesArray(Objects.requireNonNull(source).toBytesRef());
this.xContentType = Objects.requireNonNull(xContentType);
this.routing = routing;
}
public SourceToParse(String index, String type, String id, BytesReference source, XContentType xContentType) {
this(index, type, id, source, xContentType, null);
}
public BytesReference source() {
@ -70,7 +71,7 @@ public class SourceToParse {
return this.id;
}
public String routing() {
public @Nullable String routing() {
return this.routing;
}
@ -78,11 +79,6 @@ public class SourceToParse {
return this.xContentType;
}
public SourceToParse routing(String routing) {
this.routing = routing;
return this;
}
public enum Origin {
PRIMARY,
REPLICA

View File

@ -161,7 +161,6 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static org.elasticsearch.index.mapper.SourceToParse.source;
import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO;
public class IndexShard extends AbstractIndexShardComponent implements IndicesClusterStateService.Shard {
@ -715,9 +714,8 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
if (resolvedType.equals(sourceToParse.type())) {
sourceWithResolvedType = sourceToParse;
} else {
sourceWithResolvedType = SourceToParse.source(sourceToParse.index(), resolvedType, sourceToParse.id(),
sourceToParse.source(), sourceToParse.getXContentType());
sourceWithResolvedType.routing(sourceToParse.routing());
sourceWithResolvedType = new SourceToParse(sourceToParse.index(), resolvedType, sourceToParse.id(),
sourceToParse.source(), sourceToParse.getXContentType(), sourceToParse.routing());
}
operation = prepareIndex(docMapper(resolvedType), indexSettings.getIndexVersionCreated(), sourceWithResolvedType,
seqNo, opPrimaryTerm, version, versionType, origin, autoGeneratedTimeStamp, isRetry, ifSeqNo, ifPrimaryTerm);
@ -1300,8 +1298,8 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
// autoGeneratedID docs that are coming from the primary are updated correctly.
result = applyIndexOperation(engine, index.seqNo(), index.primaryTerm(), index.version(),
versionType, UNASSIGNED_SEQ_NO, 0, index.getAutoGeneratedIdTimestamp(), true, origin,
source(shardId.getIndexName(), index.type(), index.id(), index.source(),
XContentHelper.xContentType(index.source())).routing(index.routing()));
new SourceToParse(shardId.getIndexName(), index.type(), index.id(), index.source(),
XContentHelper.xContentType(index.source()), index.routing()));
break;
case DELETE:
final Translog.Delete delete = (Translog.Delete) operation;

View File

@ -50,6 +50,7 @@ import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.shard.IndexShard;
@ -69,8 +70,6 @@ import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import java.util.function.LongSupplier;
import static org.elasticsearch.index.mapper.SourceToParse.source;
public class TermVectorsService {
@ -302,8 +301,8 @@ public class TermVectorsService {
private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVectorsRequest request) throws IOException {
// parse the document, at the moment we do update the mapping, just like percolate
ParsedDocument parsedDocument =
parseDocument(indexShard, indexShard.shardId().getIndexName(), request.type(), request.doc(), request.xContentType());
ParsedDocument parsedDocument = parseDocument(indexShard, indexShard.shardId().getIndexName(), request.type(), request.doc(),
request.xContentType(), request.routing());
// select the right fields and generate term vectors
ParseContext.Document doc = parsedDocument.rootDoc();
@ -332,10 +331,11 @@ public class TermVectorsService {
}
private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc,
XContentType xContentType) {
XContentType xContentType, String routing) {
MapperService mapperService = indexShard.mapperService();
DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type);
ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(source(index, type, "_id_for_tv_api", doc, xContentType));
ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(
new SourceToParse(index, type, "_id_for_tv_api", doc, xContentType, routing));
if (docMapper.getMapping() != null) {
parsedDocument.addDynamicMappingsUpdate(docMapper.getMapping());
}

View File

@ -63,16 +63,16 @@ public class BinaryDVFieldDataTests extends AbstractFieldDataTestCase {
doc.endArray();
}
doc.endObject();
ParsedDocument d = mapper.parse(SourceToParse.source("test", "test", "1", BytesReference.bytes(doc), XContentType.JSON));
ParsedDocument d = mapper.parse(new SourceToParse("test", "test", "1", BytesReference.bytes(doc), XContentType.JSON));
writer.addDocument(d.rootDoc());
BytesRef bytes1 = randomBytes();
doc = XContentFactory.jsonBuilder().startObject().field("field", bytes1.bytes, bytes1.offset, bytes1.length).endObject();
d = mapper.parse(SourceToParse.source("test", "test", "2", BytesReference.bytes(doc), XContentType.JSON));
d = mapper.parse(new SourceToParse("test", "test", "2", BytesReference.bytes(doc), XContentType.JSON));
writer.addDocument(d.rootDoc());
doc = XContentFactory.jsonBuilder().startObject().endObject();
d = mapper.parse(SourceToParse.source("test", "test", "3", BytesReference.bytes(doc), XContentType.JSON));
d = mapper.parse(new SourceToParse("test", "test", "3", BytesReference.bytes(doc), XContentType.JSON));
writer.addDocument(d.rootDoc());
// test remove duplicate value
@ -88,7 +88,7 @@ public class BinaryDVFieldDataTests extends AbstractFieldDataTestCase {
doc.endArray();
}
doc.endObject();
d = mapper.parse(SourceToParse.source("test", "test", "4", BytesReference.bytes(doc), XContentType.JSON));
d = mapper.parse(new SourceToParse("test", "test", "4", BytesReference.bytes(doc), XContentType.JSON));
writer.addDocument(d.rootDoc());
IndexFieldData<?> indexFieldData = getForField("field");

View File

@ -91,7 +91,7 @@ public class BinaryFieldMapperTests extends ESSingleNodeTestCase {
assertTrue(CompressorFactory.isCompressed(new BytesArray(binaryValue2)));
for (byte[] value : Arrays.asList(binaryValue1, binaryValue2)) {
ParsedDocument doc = mapperService.documentMapper().parse(SourceToParse.source("test", "type", "id",
ParsedDocument doc = mapperService.documentMapper().parse(new SourceToParse("test", "type", "id",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()),
XContentType.JSON));
BytesRef indexedValue = doc.rootDoc().getBinaryValue("field");

View File

@ -71,7 +71,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", true)
@ -141,7 +141,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
.field("field", randomFrom("off", "no", "0", "on", "yes", "1"))
.endObject());
MapperParsingException ex = expectThrows(MapperParsingException.class,
() -> defaultMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)));
() -> defaultMapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON)));
assertEquals("failed to parse field [field] of type [boolean]", ex.getMessage());
}
@ -164,7 +164,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
.startObject()
.field("field", false)
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", source, XContentType.JSON));
assertNotNull(doc.rootDoc().getField("field.as_string"));
}
@ -187,7 +187,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
ParsedDocument parsedDoc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument parsedDoc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("bool1", true)

View File

@ -35,7 +35,7 @@ public class CamelCaseFieldNameTests extends ESSingleNodeTestCase {
client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get();
DocumentMapper documentMapper = index.mapperService().documentMapper("type");
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field("thisIsCamelCase", "value1")
.endObject()),

View File

@ -166,7 +166,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("completion", "suggestion")
@ -187,7 +187,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
.parse("type1", new CompressedXContent(mapping));
MapperParsingException e = expectThrows(MapperParsingException.class, () ->
defaultMapper.parse(SourceToParse.source("test", "type1", "1",
defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("completion", 1.0)
@ -220,7 +220,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("keywordfield", "key1", "key2", "key3")
@ -275,7 +275,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("suggest")
@ -331,7 +331,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("suggest", "timmy","starbucks")
@ -368,7 +368,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("geofield", "drm3btev3e86")//"41.12,-71.34"
@ -399,7 +399,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("suggest", "suggestion")
@ -431,7 +431,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("completion")
@ -469,7 +469,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("completion")
@ -509,7 +509,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("completion", "suggestion")
@ -537,7 +537,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("completion", "suggestion1", "suggestion2")
@ -561,7 +561,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("completion")
@ -587,7 +587,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("completion")
@ -630,7 +630,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService();
Mapper fieldMapper = mapperService.documentMapper().mappers().getMapper("completion");
ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("completion")
@ -655,7 +655,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("completion")
@ -693,7 +693,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("completion")
@ -733,7 +733,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
try {
defaultMapper.parse(SourceToParse.source("test", "type1", "1",
defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field1")
@ -764,7 +764,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
charsRefBuilder.append("sugg");
charsRefBuilder.setCharAt(2, '\u001F');
try {
defaultMapper.parse(SourceToParse.source("test", "type1", "1",
defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("completion", charsRefBuilder.get().toString())
@ -779,7 +779,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
charsRefBuilder.setCharAt(2, '\u0000');
try {
defaultMapper.parse(SourceToParse.source("test", "type1", "1",
defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("completion", charsRefBuilder.get().toString())
@ -794,7 +794,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
charsRefBuilder.setCharAt(2, '\u001E');
try {
defaultMapper.parse(SourceToParse.source("test", "type1", "1",
defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("completion", charsRefBuilder.get().toString())
@ -808,7 +808,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
}
// empty inputs are ignored
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("completion", " ", "")
@ -821,7 +821,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
assertThat(ignoredFields.stringValue(), equalTo("completion"));
// null inputs are ignored
ParsedDocument nullDoc = defaultMapper.parse(SourceToParse.source("test", "type1", "1",
ParsedDocument nullDoc = defaultMapper.parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("completion")

View File

@ -97,7 +97,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
.field("int_to_str_test", 42)
.endObject());
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON));
ParsedDocument parsedDoc = docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON));
ParseContext.Document doc = parsedDoc.rootDoc();
assertThat(doc.getFields("copy_test").length, equalTo(2));
assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));
@ -153,7 +153,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
.startObject("foo").startObject("bar").field("baz", "zoo").endObject().endObject()
.endObject());
ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json,
ParseContext.Document doc = docMapper.parse(new SourceToParse("test", "type1", "1", json,
XContentType.JSON)).rootDoc();
assertThat(doc.getFields("copy_test").length, equalTo(1));
assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));
@ -181,7 +181,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
.field("new_field", "bar")
.endObject());
ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json,
ParseContext.Document doc = docMapper.parse(new SourceToParse("test", "type1", "1", json,
XContentType.JSON)).rootDoc();
assertThat(doc.getFields("copy_test").length, equalTo(1));
assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));
@ -219,7 +219,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
.field("new_field", "bar")
.endObject());
ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json,
ParseContext.Document doc = docMapper.parse(new SourceToParse("test", "type1", "1", json,
XContentType.JSON)).rootDoc();
assertThat(doc.getFields("copy_test").length, equalTo(1));
assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));
@ -250,7 +250,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
.endObject());
try {
docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc();
docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc();
fail();
} catch (MapperParsingException ex) {
assertThat(ex.getMessage(), startsWith("mapping set to strict, dynamic introduction of [very] within [type1] is not allowed"));
@ -285,7 +285,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
.endObject());
try {
docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc();
docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc();
fail();
} catch (MapperParsingException ex) {
assertThat(ex.getMessage(),
@ -393,7 +393,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
.endArray()
.endObject();
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(jsonDoc), XContentType.JSON));
assertEquals(6, doc.docs().size());
@ -562,7 +562,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
.endObject());
try {
docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc();
docMapper.parse(new SourceToParse("test", "type1", "1", json, XContentType.JSON)).rootDoc();
fail();
} catch (MapperParsingException ex) {
assertThat(ex.getMessage(), startsWith("It is forbidden to create dynamic nested objects ([very]) through `copy_to`"));

View File

@ -66,7 +66,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "2016-03-11")
@ -95,7 +95,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "2016-03-11")
@ -117,7 +117,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "2016-03-11")
@ -139,7 +139,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "2016-03-11")
@ -166,7 +166,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "2016-03-99")
@ -182,7 +182,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", ":1")
@ -204,7 +204,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 1457654400)
@ -230,7 +230,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
long epochMillis = randomNonNegativeLong();
String epochFloatValue = epochMillis + "." + randomIntBetween(0, 999);
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", epochFloatValue)
@ -252,7 +252,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 1457654400)
@ -273,7 +273,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -294,7 +294,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -363,7 +363,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
final DateTimeZone randomTimeZone = randomBoolean() ? DateTimeZone.forID(randomFrom("UTC", "CET")) : randomDateTimeZone();
final DateTime randomDate = new DateTime(2016, 03, 11, 0, 0, 0, randomTimeZone);
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", DateTimeFormat.forPattern(timeZonePattern).print(randomDate))

View File

@ -177,7 +177,7 @@ public class DocumentMapperTests extends ESSingleNodeTestCase {
barrier.await();
for (int i = 0; i < 200 && stopped.get() == false; i++) {
final String fieldName = Integer.toString(i);
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test",
ParsedDocument doc = documentMapper.parse(new SourceToParse("test",
"test",
fieldName,
new BytesArray("{ \"" + fieldName + "\" : \"test\" }"),
@ -200,7 +200,7 @@ public class DocumentMapperTests extends ESSingleNodeTestCase {
while(stopped.get() == false) {
final String fieldName = lastIntroducedFieldName.get();
final BytesReference source = new BytesArray("{ \"" + fieldName + "\" : \"test\" }");
ParsedDocument parsedDoc = documentMapper.parse(SourceToParse.source("test",
ParsedDocument parsedDoc = documentMapper.parse(new SourceToParse("test",
"test",
"random",
source,

View File

@ -73,7 +73,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("foo", "1234")
.field("bar", 10)
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertNull(doc.rootDoc().getField("foo"));
assertNotNull(doc.rootDoc().getField("bar"));
assertNotNull(doc.rootDoc().getField(IdFieldMapper.NAME));
@ -98,7 +98,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("baz", 789)
.endObject()
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertNull(doc.dynamicMappingsUpdate()); // no update!
String[] values = doc.rootDoc().getValues("foo.bar.baz");
assertEquals(3, values.length);
@ -120,7 +120,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("foo.bar", 123)
.endObject());
MapperParsingException e = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals(
"Cannot add a value for field [foo.bar] since one of the intermediate objects is mapped as a nested object: [foo]",
e.getMessage());
@ -138,21 +138,21 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("foo", true)
.endObject());
MapperException exception = expectThrows(MapperException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertThat(exception.getMessage(), containsString("failed to parse field [foo] of type [long]"));
}
{
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("bar", "bar")
.endObject());
MapperException exception = expectThrows(MapperException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "2", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "2", bytes, XContentType.JSON)));
assertThat(exception.getMessage(), containsString("failed to parse field [bar] of type [boolean]"));
}
{
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("geo", 123)
.endObject());
MapperException exception = expectThrows(MapperException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "2", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "2", bytes, XContentType.JSON)));
assertThat(exception.getMessage(), containsString("failed to parse field [geo] of type [geo_shape]"));
}
@ -178,7 +178,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("foo.bar",42)
.endObject());
MapperParsingException e = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals(
"It is forbidden to create dynamic nested objects ([foo]) through `copy_to` or dots in field names",
e.getMessage());
@ -225,7 +225,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
doc.endObject();
// Verify in the case where only a single type is allowed that the _id field is added to nested documents:
ParsedDocument result = mapper.parse(SourceToParse.source("index2", "type", "1",
ParsedDocument result = mapper.parse(new SourceToParse("index2", "type", "1",
BytesReference.bytes(doc), XContentType.JSON));
assertEquals(2, result.docs().size());
// Nested document:
@ -258,7 +258,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().startObject("foo")
.field("bar", "something")
.endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertNotNull(doc.dynamicMappingsUpdate());
assertNotNull(doc.rootDoc().getField("foo.bar"));
}
@ -278,7 +278,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().startObject("foo").startObject("bar")
.field("baz", "something")
.endObject().endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertNotNull(doc.dynamicMappingsUpdate());
assertNotNull(doc.rootDoc().getField("foo.bar.baz"));
}
@ -297,7 +297,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().startObject("foo")
.field("bar", "something")
.endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertNull(doc.dynamicMappingsUpdate());
assertNull(doc.rootDoc().getField("foo.bar"));
}
@ -428,7 +428,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startArray().value(0).value(0).endArray()
.startArray().value(1).value(1).endArray()
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo").length);
}
@ -446,7 +446,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(0)
.value(1)
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(4, doc.rootDoc().getFields("foo").length);
}
@ -461,7 +461,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(0)
.value(1)
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(4, doc.rootDoc().getFields("foo").length);
}
@ -477,7 +477,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(0)
.value(1)
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(0, doc.rootDoc().getFields("foo").length);
}
@ -494,7 +494,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(1)
.endArray().endObject());
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
}
@ -511,7 +511,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startArray().value(0).value(0).endArray()
.startArray().value(1).value(1).endArray()
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo").length);
}
@ -527,7 +527,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(0)
.value(1)
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(4, doc.rootDoc().getFields("foo").length);
}
@ -545,7 +545,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().startObject("foo")
.field("bar", "baz")
.endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo.bar").length);
}
@ -560,7 +560,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().startObject("foo")
.field("bar", "baz")
.endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(0, doc.rootDoc().getFields("foo.bar").length);
}
@ -576,7 +576,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("bar", "baz")
.endObject().endObject());
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
}
@ -591,7 +591,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject()
.field("bar", "baz")
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(0, doc.rootDoc().getFields("bar").length);
}
@ -607,7 +607,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("bar", "baz")
.endObject());
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage());
}
@ -622,7 +622,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject()
.field("bar", (String) null)
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(0, doc.rootDoc().getFields("bar").length);
}
@ -638,7 +638,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("bar", (String) null)
.endObject());
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage());
}
@ -652,7 +652,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("foo", (Long) null)
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(0, doc.rootDoc().getFields("foo").length);
}
@ -667,7 +667,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(0)
.value(1)
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -694,7 +694,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(0)
.value(1)
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -720,7 +720,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(0)
.value(1)
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -747,7 +747,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(1)
.endArray().endObject());
MapperParsingException exception = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. "
+ "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage());
}
@ -764,7 +764,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(0)
.value(1)
.endArray().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length);
}
@ -781,7 +781,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.value(1)
.endArray().endObject());
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
}
@ -794,7 +794,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("foo.bar.baz", 0)
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -819,7 +819,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("foo.bar.baz", 0)
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -843,7 +843,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("foo.bar.baz", 0)
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -868,7 +868,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().field("foo.bar.baz", 0)
.endObject());
MapperParsingException exception = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. "
+ "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage());
}
@ -883,7 +883,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("foo.bar.baz", 0)
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length);
}
@ -898,7 +898,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().field("foo.bar.baz", 0)
.endObject());
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
}
@ -912,7 +912,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().startObject("foo.bar.baz")
.field("a", 0)
.endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -941,7 +941,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().startObject("foo.bar.baz")
.field("a", 0)
.endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -965,7 +965,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz")
.field("a", 0).endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
@ -992,7 +992,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz")
.field("a", 0).endObject().endObject());
MapperParsingException exception = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. "
+ "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage());
@ -1009,7 +1009,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.startObject().startObject("foo.bar.baz")
.field("a", 0)
.endObject().endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
assertEquals(0, doc.rootDoc().getFields("foo.bar.baz.a").length);
}
@ -1025,7 +1025,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("a", 0)
.endObject().endObject());
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
}
@ -1036,12 +1036,12 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("_ttl", 0).endObject());
MapperParsingException e = expectThrows(MapperParsingException.class, () ->
mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertTrue(e.getMessage(), e.getMessage().contains("cannot be added inside a document"));
BytesReference bytes2 = BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field("foo._ttl", 0).endObject());
mapper.parse(SourceToParse.source("test", "type", "1", bytes2, XContentType.JSON)); // parses without error
mapper.parse(new SourceToParse("test", "type", "1", bytes2, XContentType.JSON)); // parses without error
}
public void testSimpleMapper() throws Exception {
@ -1053,10 +1053,10 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
indexService.mapperService()).build(indexService.mapperService());
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
assertThat(doc.get(docMapper.mappers().getMapper("name.first").name()), equalTo("shay"));
doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
}
public void testParseToJsonAndParse() throws Exception {
@ -1067,7 +1067,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
// reparse it
DocumentMapper builtDocMapper = parser.parse("person", new CompressedXContent(builtMapping));
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
Document doc = builtDocMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = builtDocMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
assertThat(doc.getBinaryValue(docMapper.idFieldMapper().name()), equalTo(Uid.encodeId("1")));
assertThat(doc.get(docMapper.mappers().getMapper("name.first").name()), equalTo("shay"));
}
@ -1080,7 +1080,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
assertThat(doc.getBinaryValue(docMapper.idFieldMapper().name()), equalTo(Uid.encodeId("1")));
assertThat(doc.get(docMapper.mappers().getMapper("name.first").name()), equalTo("shay"));
}
@ -1090,7 +1090,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser()
.parse("person", new CompressedXContent(mapping));
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1-notype-noid.json"));
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
assertThat(doc.getBinaryValue(docMapper.idFieldMapper().name()), equalTo(Uid.encodeId("1")));
assertThat(doc.get(docMapper.mappers().getMapper("name.first").name()), equalTo("shay"));
}
@ -1117,7 +1117,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
BytesReference json = new BytesArray("".getBytes(StandardCharsets.UTF_8));
try {
docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
fail("this point is never reached");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), equalTo("failed to parse, document is empty"));
@ -1130,7 +1130,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("test1", "value1")
@ -1150,7 +1150,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject().startObject("type")
.field("test1", "value1")
@ -1170,7 +1170,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("type", "value_type")
@ -1192,7 +1192,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject().startObject("type")
.field("type", "value_type")
@ -1214,7 +1214,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("type").field("type_field", "type_value").endObject()
@ -1236,7 +1236,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject().startObject("type")
.startObject("type").field("type_field", "type_value").endObject()
@ -1258,7 +1258,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject().startObject("type")
.field("test1", "value1")
@ -1280,7 +1280,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject().startObject("type")
.field("test1", "value1")
@ -1302,7 +1302,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("test1", "value1")
@ -1325,7 +1325,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject().startObject("type")
.field("test1", "value1")
@ -1356,7 +1356,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
// Even though we matched the dynamic format, we do not match on numbers,
// which are too likely to be false positives
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
Mapping update = doc.dynamicMappingsUpdate();
assertNotNull(update);
Mapper dateMapper = update.root().getMapper("foo");
@ -1378,7 +1378,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.endObject());
// We should have generated a date field
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON));
Mapping update = doc.dynamicMappingsUpdate();
assertNotNull(update);
Mapper dateMapper = update.root().getMapper("foo");
@ -1481,7 +1481,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("alias-field", "value")
.endObject());
MapperParsingException exception = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("Cannot write to a field alias [alias-field].", exception.getCause().getMessage());
}
@ -1514,7 +1514,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("text-field", "value")
.endObject());
MapperParsingException exception = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("Cannot copy to a field alias [alias-field].", exception.getCause().getMessage());
}
@ -1545,7 +1545,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.endObject()
.endObject());
MapperParsingException exception = expectThrows(MapperParsingException.class,
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
() -> mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)));
assertEquals("Could not dynamically add mapping for field [alias-field.dynamic-field]. "
+ "Existing mapping for [alias-field] must be of type object but found [alias].", exception.getMessage());
@ -1564,7 +1564,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
.field("foo", "1234")
.endObject());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "_doc", "1", bytes, XContentType.JSON));
ParsedDocument doc = mapper.parse(new SourceToParse("test", "_doc", "1", bytes, XContentType.JSON));
assertNull(doc.dynamicMappingsUpdate()); // no update since we reused the existing type
}
}

View File

@ -50,7 +50,7 @@ public class DoubleIndexingDocTests extends ESSingleNodeTestCase {
QueryShardContext context = index.newQueryShardContext(0, null, () -> 0L, null);
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field1", "value1")

View File

@ -70,7 +70,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(jsonBuilder()
.startObject()
.field("field1", "value1")
@ -93,7 +93,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(jsonBuilder()
.startObject()
.field("field1", "value1")
@ -118,7 +118,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
.parse("type", new CompressedXContent(mapping));
StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class,
() -> defaultMapper.parse(SourceToParse.source("test", "type", "1",
() -> defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(jsonBuilder()
.startObject()
.field("field1", "value1")
@ -128,7 +128,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed"));
e = expectThrows(StrictDynamicMappingException.class,
() -> defaultMapper.parse(SourceToParse.source("test", "type", "1",
() -> defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field1", "value1")
@ -151,7 +151,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(jsonBuilder()
.startObject().startObject("obj1")
.field("field1", "value1")
@ -178,7 +178,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
.parse("type", new CompressedXContent(mapping));
StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () ->
defaultMapper.parse(SourceToParse.source("test", "type", "1",
defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(jsonBuilder()
.startObject().startObject("obj1")
.field("field1", "value1")
@ -207,7 +207,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
.settings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT))
.numberOfShards(1).numberOfReplicas(0).build();
IndexSettings settings = new IndexSettings(build, Settings.EMPTY);
SourceToParse source = SourceToParse.source("test", mapper.type(), "some_id",
SourceToParse source = new SourceToParse("test", mapper.type(), "some_id",
BytesReference.bytes(builder), builder.contentType());
try (XContentParser xContentParser = createParser(JsonXContent.jsonXContent, source.source())) {
ParseContext.InternalParseContext ctx = new ParseContext.InternalParseContext(settings, parser, mapper, source, xContentParser);
@ -561,7 +561,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
XContentBuilder json = XContentFactory.jsonBuilder().startObject()
.field("field", "foo")
.endObject();
SourceToParse source = SourceToParse.source("test", "_doc", "1", BytesReference.bytes(json), json.contentType());
SourceToParse source = new SourceToParse("test", "_doc", "1", BytesReference.bytes(json), json.contentType());
DocumentMapper mapper = indexService.mapperService().documentMapper("_doc");
assertNull(mapper.mappers().getMapper("field.raw"));
ParsedDocument parsed = mapper.parse(source);
@ -596,7 +596,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
.field("baz", (double) 3.2f) // double that can be accurately represented as a float
.field("quux", "3.2") // float detected through numeric detection
.endObject());
ParsedDocument parsedDocument = mapper.parse(SourceToParse.source("index", "type", "id",
ParsedDocument parsedDocument = mapper.parse(new SourceToParse("index", "type", "id",
source, builder.contentType()));
Mapping update = parsedDocument.dynamicMappingsUpdate();
assertNotNull(update);
@ -615,7 +615,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get();
DocumentMapper defaultMapper = index.mapperService().documentMapper("type");
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("s_long", "100")
@ -642,7 +642,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get();
DocumentMapper defaultMapper = index.mapperService().documentMapper("type");
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("s_long", "100")
@ -691,7 +691,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get();
DocumentMapper defaultMapper = index.mapperService().documentMapper("type");
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("date1", "2016-11-20")

View File

@ -45,7 +45,7 @@ public class DynamicMappingVersionTests extends ESSingleNodeTestCase {
.documentMapperWithAutoCreate("my-type").getDocumentMapper();
ParsedDocument parsedDoc = documentMapper.parse(
SourceToParse.source("my-index", "my-type", "1", BytesReference
new SourceToParse("my-index", "my-type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("foo", 3)

View File

@ -50,7 +50,7 @@ public class DynamicTemplatesTests extends ESSingleNodeTestCase {
DocumentMapper docMapper = mapperService.documentMapper("person");
builder = JsonXContent.contentBuilder();
builder.startObject().field("s", "hello").field("l", 1).endObject();
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", BytesReference.bytes(builder),
ParsedDocument parsedDoc = docMapper.parse(new SourceToParse("test", "person", "1", BytesReference.bytes(builder),
XContentType.JSON));
client().admin().indices().preparePutMapping("test").setType("person")
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
@ -70,7 +70,7 @@ public class DynamicTemplatesTests extends ESSingleNodeTestCase {
client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get();
DocumentMapper docMapper = index.mapperService().documentMapper("person");
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json");
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json),
ParsedDocument parsedDoc = docMapper.parse(new SourceToParse("test", "person", "1", new BytesArray(json),
XContentType.JSON));
client().admin().indices().preparePutMapping("test").setType("person")
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
@ -129,7 +129,7 @@ public class DynamicTemplatesTests extends ESSingleNodeTestCase {
client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get();
DocumentMapper docMapper = index.mapperService().documentMapper("person");
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json");
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json),
ParsedDocument parsedDoc = docMapper.parse(new SourceToParse("test", "person", "1", new BytesArray(json),
XContentType.JSON));
client().admin().indices().preparePutMapping("test").setType("person")
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();

View File

@ -87,7 +87,7 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase {
.endObject().endObject())
));
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -146,7 +146,7 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase {
.endObject()
.endObject().endObject().endObject())));
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -213,7 +213,7 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase {
.endObject()
.endObject().endObject().endObject())));
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")

View File

@ -82,7 +82,7 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("a", "100")
@ -106,7 +106,7 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class);
assertTrue(fieldNamesMapper.fieldType().isEnabled());
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -125,7 +125,7 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class);
assertFalse(fieldNamesMapper.fieldType().isEnabled());
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")

View File

@ -40,7 +40,7 @@ public class GenericStoreDynamicTemplateTests extends ESSingleNodeTestCase {
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-data.json");
ParsedDocument parsedDoc = mapperService.documentMapper().parse(
SourceToParse.source("test", "person", "1", new BytesArray(json), XContentType.JSON));
new SourceToParse("test", "person", "1", new BytesArray(json), XContentType.JSON));
client().admin().indices().preparePutMapping("test").setType("person")
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
Document doc = parsedDoc.rootDoc();

View File

@ -65,7 +65,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("point", stringEncode(1.3, 1.2))
@ -82,7 +82,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("point").field("lat", 1.2).field("lon", 1.3).endObject()
@ -99,7 +99,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("point")
@ -121,7 +121,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("point", "1.2,1.3")
@ -139,7 +139,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("point", "1.2,1.3,10.0")
@ -157,7 +157,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
SourceToParse source = SourceToParse.source("test", "type", "1",
SourceToParse source = new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("point", "1.2,1.3,10.0")
@ -175,7 +175,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("point", "1.2,1.3")
@ -191,7 +191,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("point")
@ -213,7 +213,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("point").value(1.3).value(1.2).endArray()
@ -231,7 +231,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("point").value(1.3).value(1.2).endArray()
@ -248,7 +248,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("point").value(1.3).value(1.2).endArray()
@ -268,7 +268,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startArray("point")
@ -381,7 +381,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
Object nullValue = ((GeoPointFieldMapper) fieldMapper).fieldType().nullValue();
assertThat(nullValue, equalTo(new GeoPoint(1, 2)));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("location")
@ -391,7 +391,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
assertThat(doc.rootDoc().getField("location"), notNullValue());
BytesRef defaultValue = doc.rootDoc().getField("location").binaryValue();
doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("location", "1, 2")
@ -400,7 +400,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
// Shouldn't matter if we specify the value explicitly or use null value
assertThat(defaultValue, equalTo(doc.rootDoc().getField("location").binaryValue()));
doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("location", "3, 4")
@ -422,7 +422,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("location", "1234.333")
@ -445,7 +445,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
.parse("type", new CompressedXContent(mapping));
MapperParsingException ex = expectThrows(MapperParsingException.class,
() -> defaultMapper.parse(SourceToParse.source("test", "type", "1",
() -> defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("location", "1234.333")
@ -469,57 +469,57 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("location", "1234.333").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("lat", "-").field("lon", 1.3).endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("lat", 1.3).field("lon", "-").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("location", "-,1.3").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("location", "1.3,-").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("lat", "NaN").field("lon", "NaN").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("lat", 12).field("lon", "NaN").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("lat", "NaN").field("lon", 10).endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("location", "NaN,NaN").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("location", "10,NaN").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());
assertThat(defaultMapper.parse(SourceToParse.source("test", "type", "1",
assertThat(defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("location", "NaN,12").endObject()
), XContentType.JSON)).rootDoc().getField("location"), nullValue());

View File

@ -50,7 +50,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase {
.parse("type", new CompressedXContent(mapping));
try {
docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("_id", "1").endObject()), XContentType.JSON));
fail("Expected failure to parse metadata field");
} catch (MapperParsingException e) {
@ -62,7 +62,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase {
Settings indexSettings = Settings.EMPTY;
MapperService mapperService = createIndex("test", indexSettings).mapperService();
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE);
ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id",
ParsedDocument document = mapper.parse(new SourceToParse("index", "type", "id",
new BytesArray("{}"), XContentType.JSON));
IndexableField[] fields = document.rootDoc().getFields(IdFieldMapper.NAME);
assertEquals(1, fields.length);

View File

@ -47,7 +47,7 @@ public class IndexFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")

View File

@ -68,7 +68,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "::1")
@ -97,7 +97,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "::1")
@ -119,7 +119,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "::1")
@ -142,7 +142,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "::1")
@ -170,7 +170,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", ":1")
@ -185,7 +185,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", ":1")
@ -210,7 +210,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -231,7 +231,7 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")

View File

@ -60,7 +60,7 @@ public class IpRangeFieldMapperTests extends ESSingleNodeTestCase {
cases.put("192.168.0.0/17", "192.168.127.255");
for (final Map.Entry<String, String> entry : cases.entrySet()) {
ParsedDocument doc =
mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", entry.getKey())
.endObject()),

View File

@ -45,7 +45,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase {
BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject());
Document doc = mapperService.documentMapper().parse(
SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
@ -61,7 +61,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase {
assertThat(mapperService.fullName("name.not_indexed2"), nullValue());
assertThat(mapperService.fullName("name.not_indexed3"), nullValue());
doc = mapperService.documentMapper().parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
doc = mapperService.documentMapper().parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
@ -99,7 +99,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase {
BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject());
Document doc = mapperService.documentMapper().parse(
SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
@ -117,7 +117,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase {
assertThat(mapperService.fullName("name.not_indexed3"), nullValue());
doc = mapperService.documentMapper().parse(
SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");

View File

@ -110,7 +110,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -147,7 +147,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "elk")
@ -157,7 +157,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
IndexableField[] fields = doc.rootDoc().getFields("field");
assertEquals(2, fields.length);
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "elasticsearch")
@ -176,7 +176,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -192,7 +192,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.endObject()),
@ -201,7 +201,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
IndexableField[] fields = doc.rootDoc().getFields("field");
assertEquals(0, fields.length);
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -222,7 +222,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -243,7 +243,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -265,7 +265,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -287,7 +287,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -333,7 +333,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -358,7 +358,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "AbC")

View File

@ -64,7 +64,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
Document doc = mapperService.documentMapper().parse(
SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));
@ -140,7 +140,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
Document doc = docMapper.parse(new SourceToParse("test", "person", "1", json, XContentType.JSON)).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));

View File

@ -63,7 +63,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -73,7 +73,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
assertThat(doc.docs().size(), equalTo(1));
doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -96,7 +96,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
assertThat(nested1Mapper.nested().isNested(), equalTo(true));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -112,7 +112,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
assertThat(doc.docs().get(1).get("field"), equalTo("value"));
doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -154,7 +154,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false));
assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -215,7 +215,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true));
assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -278,7 +278,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true));
assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -339,7 +339,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false));
assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(true));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -398,7 +398,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().startArray("nested1")
.startObject().startArray("nested2").startObject().field("foo", "bar")
@ -432,7 +432,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().startArray("nested1")
.startObject().startArray("nested2")
@ -460,7 +460,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
assertThat(nested1Mapper.nested().isNested(), equalTo(true));
assertThat(nested1Mapper.dynamic(), equalTo(Dynamic.STRICT));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -568,7 +568,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
docBuilder.endArray();
}
docBuilder.endObject();
SourceToParse source1 = SourceToParse.source("test1", "type", "1",
SourceToParse source1 = new SourceToParse("test1", "type", "1",
BytesReference.bytes(docBuilder), XContentType.JSON);
MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source1));
assertEquals(
@ -601,7 +601,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
docBuilder.endArray();
}
docBuilder.endObject();
SourceToParse source1 = SourceToParse.source("test1", "type", "1",
SourceToParse source1 = new SourceToParse("test1", "type", "1",
BytesReference.bytes(docBuilder), XContentType.JSON);
ParsedDocument doc = docMapper.parse(source1);
assertThat(doc.docs().size(), equalTo(3));
@ -619,7 +619,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
docBuilder2.endArray();
}
docBuilder2.endObject();
SourceToParse source2 = SourceToParse.source("test1", "type", "2",
SourceToParse source2 = new SourceToParse("test1", "type", "2",
BytesReference.bytes(docBuilder2), XContentType.JSON);
MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2));
assertEquals(
@ -657,7 +657,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
docBuilder.endArray();
}
docBuilder.endObject();
SourceToParse source1 = SourceToParse.source("test1", "type", "1",
SourceToParse source1 = new SourceToParse("test1", "type", "1",
BytesReference.bytes(docBuilder), XContentType.JSON);
ParsedDocument doc = docMapper.parse(source1);
assertThat(doc.docs().size(), equalTo(3));
@ -680,7 +680,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
}
docBuilder2.endObject();
SourceToParse source2 = SourceToParse.source("test1", "type", "2",
SourceToParse source2 = new SourceToParse("test1", "type", "2",
BytesReference.bytes(docBuilder2), XContentType.JSON);
MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2));
assertEquals(
@ -714,7 +714,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
assertThat(nested1Mapper.nested().isNested(), equalTo(true));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")

View File

@ -39,7 +39,7 @@ public class NullValueObjectMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("obj1").endObject()
@ -49,7 +49,7 @@ public class NullValueObjectMappingTests extends ESSingleNodeTestCase {
assertThat(doc.rootDoc().get("value1"), equalTo("test1"));
doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("obj1")
@ -59,7 +59,7 @@ public class NullValueObjectMappingTests extends ESSingleNodeTestCase {
assertThat(doc.rootDoc().get("value1"), equalTo("test1"));
doc = defaultMapper.parse(SourceToParse.source("test", "type", "1",
doc = defaultMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("obj1").field("field", "value").endObject()

View File

@ -56,7 +56,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 123)
@ -84,7 +84,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 123)
@ -107,7 +107,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 123)
@ -131,7 +131,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", 123)
@ -160,7 +160,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "123")
@ -183,7 +183,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(mapping, mapper2.mappingSource().toString());
ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference
ThrowingRunnable runnable = () -> mapper2.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "123")
@ -203,7 +203,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "7.89")
@ -230,7 +230,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ThrowingRunnable runnable = () -> mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "a")
@ -246,7 +246,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper2.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "a")
@ -308,7 +308,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -335,7 +335,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -422,7 +422,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
}
private void parseRequest(NumberType type, BytesReference content) throws IOException {
createDocumentMapper(type).parse(SourceToParse.source("test", "type", "1", content, XContentType.JSON));
createDocumentMapper(type).parse(new SourceToParse("test", "type", "1", content, XContentType.JSON));
}
private DocumentMapper createDocumentMapper(NumberType type) throws IOException {

View File

@ -43,7 +43,7 @@ public class ObjectMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
defaultMapper.parse(SourceToParse.source("test", "type", "1", new BytesArray(" {\n" +
defaultMapper.parse(new SourceToParse("test", "type", "1", new BytesArray(" {\n" +
" \"object\": {\n" +
" \"array\":[\n" +
" {\n" +

View File

@ -40,7 +40,7 @@ public class PathMatchDynamicTemplateTests extends ESSingleNodeTestCase {
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json");
ParsedDocument parsedDoc = mapperService.documentMapper().parse(
SourceToParse.source("test", "person", "1", new BytesArray(json), XContentType.JSON));
new SourceToParse("test", "person", "1", new BytesArray(json), XContentType.JSON));
client().admin().indices().preparePutMapping("test").setType("person")
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
Document doc = parsedDoc.rootDoc();

View File

@ -121,7 +121,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping)));
assertEquals(Strings.toString(mapping), mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.field(getFromField(), getFrom(type))
@ -152,7 +152,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping)));
assertEquals(Strings.toString(mapping), mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.field(getFromField(), getFrom(type))
@ -176,7 +176,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping)));
assertEquals(Strings.toString(mapping), mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.field(getFromField(), getFrom(type))
@ -202,7 +202,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping)));
assertEquals(Strings.toString(mapping), mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.field(getFromField(), getFrom(type))
@ -241,7 +241,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(Strings.toString(mapping), mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.field(getFromField(), getFrom(type))
@ -267,7 +267,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(Strings.toString(mapping), mapper2.mappingSource().toString());
ThrowingRunnable runnable = () -> mapper2
.parse(SourceToParse.source(
.parse(new SourceToParse(
"test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("field")
.field(getFromField(), "5.2").field(getToField(), "10").endObject().endObject()),
XContentType.JSON));
@ -287,7 +287,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(Strings.toString(mapping), mapper.mappingSource().toString());
ParsedDocument doc1 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc1 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.field(GT_FIELD.getPreferredName(), "2.34")
@ -296,7 +296,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
.endObject()),
XContentType.JSON));
ParsedDocument doc2 = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc2 = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.field(GT_FIELD.getPreferredName(), "2")
@ -324,7 +324,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(Strings.toString(mapping), mapper.mappingSource().toString());
// test null value for min and max
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.nullField(getFromField())
@ -339,7 +339,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertThat(storedField.stringValue(), containsString(expected));
// test null max value
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.field(getFromField(), getFrom(type))
@ -367,7 +367,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertThat(storedField.stringValue(), containsString(strVal));
// test null range
doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.nullField("field")
@ -394,7 +394,7 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
assertEquals(Strings.toString(mapping), mapper.mappingSource().toString());
// test no bounds specified
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.endObject()

View File

@ -37,12 +37,12 @@ public class RoutingFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
.endObject()),
XContentType.JSON).routing("routing_value"));
XContentType.JSON, "routing_value"));
assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value"));
assertThat(doc.rootDoc().get("field"), equalTo("value"));
@ -54,7 +54,7 @@ public class RoutingFieldMapperTests extends ESSingleNodeTestCase {
.parse("type", new CompressedXContent(mapping));
try {
docMapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder()
.startObject().field("_routing", "foo").endObject()),XContentType.JSON));
fail("Expected failure to parse metadata field");
} catch (MapperParsingException e) {

View File

@ -54,7 +54,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.field("field", "value")
.endObject()),
@ -63,7 +63,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
assertThat(XContentFactory.xContentType(doc.source().toBytesRef().bytes), equalTo(XContentType.JSON));
documentMapper = parser.parse("type", new CompressedXContent(mapping));
doc = documentMapper.parse(SourceToParse.source("test", "type", "1",
doc = documentMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.smileBuilder().startObject()
.field("field", "value")
.endObject()),
@ -80,7 +80,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.startObject("path1").field("field1", "value1").endObject()
.startObject("path2").field("field2", "value2").endObject()
@ -104,7 +104,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1",
ParsedDocument doc = documentMapper.parse(new SourceToParse("test", "type", "1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
.startObject("path1").field("field1", "value1").endObject()
.startObject("path2").field("field2", "value2").endObject()
@ -216,7 +216,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
.parse("type", new CompressedXContent(mapping));
try {
documentMapper.parse(SourceToParse.source("test", "type", "1",
documentMapper.parse(new SourceToParse("test", "type", "1",
new BytesArray("{}}"), XContentType.JSON)); // extra end object (invalid JSON)
fail("Expected parse exception");
} catch (MapperParsingException e) {

View File

@ -64,7 +64,7 @@ public class StoredNumericValuesTests extends ESSingleNodeTestCase {
MapperService mapperService = createIndex("test").mapperService();
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE);
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field1", 1)

View File

@ -103,7 +103,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -135,7 +135,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -156,7 +156,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -179,7 +179,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "1234")
@ -210,7 +210,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
for (String option : supportedOptions.keySet()) {
jsonDoc.field(option, "1234");
}
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference.bytes(jsonDoc.endObject()),
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(jsonDoc.endObject()),
XContentType.JSON));
for (Map.Entry<String, IndexOptions> entry : supportedOptions.entrySet()) {
@ -232,7 +232,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference
SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("field", new String[] {"a", "b"})
@ -274,7 +274,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
assertEquals(mapping, mapper.mappingSource().toString());
SourceToParse sourceToParse = SourceToParse.source("test", "type", "1", BytesReference
SourceToParse sourceToParse = new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("field", new String[]{"a", "b"})
@ -433,7 +433,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = defaultMapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field1", "1234")
@ -765,7 +765,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
new Term("synfield._index_phrase", "motor dog")})
.build()));
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "Some English text that is going to be very useful")
@ -830,7 +830,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
assertThat(mapper.mappers().getMapper("field._index_prefix").toString(), containsString("prefixChars=2:10"));
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", BytesReference
ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.field("field", "Some English text that is going to be very useful")

View File

@ -59,7 +59,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase {
public static void testDocValues(Function<String, IndexService> createIndex) throws IOException {
MapperService mapperService = createIndex.apply("test").mapperService();
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE);
ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON));
ParsedDocument document = mapper.parse(new SourceToParse("index", "type", "id", new BytesArray("{}"), XContentType.JSON));
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
@ -84,7 +84,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase {
Settings indexSettings = Settings.EMPTY;
MapperService mapperService = createIndex("test", indexSettings).mapperService();
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE);
ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON));
ParsedDocument document = mapper.parse(new SourceToParse("index", "type", "id", new BytesArray("{}"), XContentType.JSON));
assertEquals(Collections.<IndexableField>emptyList(), Arrays.asList(document.rootDoc().getFields(TypeFieldMapper.NAME)));
}
}

View File

@ -197,7 +197,7 @@ public class RecoveryDuringReplicationTests extends ESIndexLevelReplicationTestC
1,
randomNonNegativeLong(),
false,
SourceToParse.source("index", "type", "replica", new BytesArray("{}"), XContentType.JSON));
new SourceToParse("index", "type", "replica", new BytesArray("{}"), XContentType.JSON));
shards.promoteReplicaToPrimary(promotedReplica).get();
oldPrimary.close("demoted", randomBoolean());
oldPrimary.store().close();
@ -210,7 +210,7 @@ public class RecoveryDuringReplicationTests extends ESIndexLevelReplicationTestC
promotedReplica.applyIndexOperationOnPrimary(
Versions.MATCH_ANY,
VersionType.INTERNAL,
SourceToParse.source("index", "type", "primary", new BytesArray("{}"), XContentType.JSON),
new SourceToParse("index", "type", "primary", new BytesArray("{}"), XContentType.JSON),
SequenceNumbers.UNASSIGNED_SEQ_NO, 0, randomNonNegativeLong(),
false);
}

View File

@ -357,7 +357,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
.setSource("{}", XContentType.JSON).setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get();
assertFalse(shard.shouldPeriodicallyFlush());
shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL,
SourceToParse.source("test", "test", "1", new BytesArray("{}"), XContentType.JSON),
new SourceToParse("test", "test", "1", new BytesArray("{}"), XContentType.JSON),
SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
assertTrue(shard.shouldPeriodicallyFlush());
final Translog translog = getTranslog(shard);
@ -407,7 +407,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
for (int i = 0; i < numberOfDocuments; i++) {
assertThat(translog.currentFileGeneration(), equalTo(generation + rolls));
final Engine.IndexResult result = shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL,
SourceToParse.source("test", "test", "1", new BytesArray("{}"), XContentType.JSON),
new SourceToParse("test", "test", "1", new BytesArray("{}"), XContentType.JSON),
SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
final Translog.Location location = result.getTranslogLocation();
shard.afterWriteOperation();

View File

@ -1790,15 +1790,15 @@ public class IndexShardTests extends IndexShardTestCase {
shard.applyDeleteOperationOnReplica(1, 2, "_doc", "id");
shard.getEngine().rollTranslogGeneration(); // isolate the delete in it's own generation
shard.applyIndexOperationOnReplica(0, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(shard.shardId().getIndexName(), "_doc", "id", new BytesArray("{}"), XContentType.JSON));
shard.applyIndexOperationOnReplica(3, 3, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-3", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(shard.shardId().getIndexName(), "_doc", "id-3", new BytesArray("{}"), XContentType.JSON));
// Flushing a new commit with local checkpoint=1 allows to skip the translog gen #1 in recovery.
shard.flush(new FlushRequest().force(true).waitIfOngoing(true));
shard.applyIndexOperationOnReplica(2, 3, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-2", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(shard.shardId().getIndexName(), "_doc", "id-2", new BytesArray("{}"), XContentType.JSON));
shard.applyIndexOperationOnReplica(5, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(shard.shardId().getIndexName(), "_doc", "id-5", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(shard.shardId().getIndexName(), "_doc", "id-5", new BytesArray("{}"), XContentType.JSON));
final int translogOps;
if (randomBoolean()) {
@ -1912,7 +1912,7 @@ public class IndexShardTests extends IndexShardTestCase {
// start a replica shard and index the second doc
final IndexShard otherShard = newStartedShard(false);
updateMappings(otherShard, shard.indexSettings().getIndexMetaData());
SourceToParse sourceToParse = SourceToParse.source(shard.shardId().getIndexName(), "_doc", "1",
SourceToParse sourceToParse = new SourceToParse(shard.shardId().getIndexName(), "_doc", "1",
new BytesArray("{}"), XContentType.JSON);
otherShard.applyIndexOperationOnReplica(1, 1,
IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse);
@ -2033,11 +2033,11 @@ public class IndexShardTests extends IndexShardTestCase {
final String indexName = shard.shardId().getIndexName();
// Index #0, index #1
shard.applyIndexOperationOnReplica(0, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "_doc", "doc-0", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "_doc", "doc-0", new BytesArray("{}"), XContentType.JSON));
flushShard(shard);
shard.updateGlobalCheckpointOnReplica(0, "test"); // stick the global checkpoint here.
shard.applyIndexOperationOnReplica(1, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "_doc", "doc-1", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "_doc", "doc-1", new BytesArray("{}"), XContentType.JSON));
flushShard(shard);
assertThat(getShardDocUIDs(shard), containsInAnyOrder("doc-0", "doc-1"));
// Here we try to increase term (i.e. a new primary is promoted) without rolling back a replica so we can keep stale operations
@ -2047,7 +2047,7 @@ public class IndexShardTests extends IndexShardTestCase {
shard.getEngine().rollTranslogGeneration();
shard.markSeqNoAsNoop(1, "test");
shard.applyIndexOperationOnReplica(2, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "_doc", "doc-2", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "_doc", "doc-2", new BytesArray("{}"), XContentType.JSON));
flushShard(shard);
assertThat(getShardDocUIDs(shard), containsInAnyOrder("doc-0", "doc-1", "doc-2"));
closeShard(shard, false);
@ -3037,7 +3037,7 @@ public class IndexShardTests extends IndexShardTestCase {
for (int i = offset + 1; i < operations; i++) {
if (!rarely() || i == operations - 1) { // last operation can't be a gap as it's not a gap anymore
final String id = Integer.toString(i);
SourceToParse sourceToParse = SourceToParse.source(indexShard.shardId().getIndexName(), "_doc", id,
SourceToParse sourceToParse = new SourceToParse(indexShard.shardId().getIndexName(), "_doc", id,
new BytesArray("{}"), XContentType.JSON);
indexShard.applyIndexOperationOnReplica(i, 1,
IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse);

View File

@ -80,7 +80,7 @@ public class PrimaryReplicaSyncerTests extends IndexShardTestCase {
for (int i = 0; i < numDocs; i++) {
// Index doc but not advance local checkpoint.
shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL,
SourceToParse.source(shard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON),
new SourceToParse(shard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON),
SequenceNumbers.UNASSIGNED_SEQ_NO, 0,
randomBoolean() ? IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP : randomNonNegativeLong(), true);
}
@ -150,7 +150,7 @@ public class PrimaryReplicaSyncerTests extends IndexShardTestCase {
for (int i = 0; i < numDocs; i++) {
// Index doc but not advance local checkpoint.
shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL,
SourceToParse.source(shard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON),
new SourceToParse(shard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"), XContentType.JSON),
SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
}

View File

@ -132,19 +132,19 @@ public class RecoveryTests extends ESIndexLevelReplicationTestCase {
getTranslog(orgReplica).rollGeneration(); // isolate the delete in it's own generation
// index #0
orgReplica.applyIndexOperationOnReplica(0, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "type", "id", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "type", "id", new BytesArray("{}"), XContentType.JSON));
// index #3
orgReplica.applyIndexOperationOnReplica(3, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "type", "id-3", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "type", "id-3", new BytesArray("{}"), XContentType.JSON));
// Flushing a new commit with local checkpoint=1 allows to delete the translog gen #1.
orgReplica.flush(new FlushRequest().force(true).waitIfOngoing(true));
// index #2
orgReplica.applyIndexOperationOnReplica(2, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "type", "id-2", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "type", "id-2", new BytesArray("{}"), XContentType.JSON));
orgReplica.updateGlobalCheckpointOnReplica(3L, "test");
// index #5 -> force NoOp #4.
orgReplica.applyIndexOperationOnReplica(5, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON));
final int translogOps;
if (randomBoolean()) {
@ -196,19 +196,19 @@ public class RecoveryTests extends ESIndexLevelReplicationTestCase {
orgReplica.flush(new FlushRequest().force(true)); // isolate delete#1 in its own translog generation and lucene segment
// index #0
orgReplica.applyIndexOperationOnReplica(0, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "type", "id", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "type", "id", new BytesArray("{}"), XContentType.JSON));
// index #3
orgReplica.applyIndexOperationOnReplica(3, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "type", "id-3", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "type", "id-3", new BytesArray("{}"), XContentType.JSON));
// Flushing a new commit with local checkpoint=1 allows to delete the translog gen #1.
orgReplica.flush(new FlushRequest().force(true).waitIfOngoing(true));
// index #2
orgReplica.applyIndexOperationOnReplica(2, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "type", "id-2", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "type", "id-2", new BytesArray("{}"), XContentType.JSON));
orgReplica.updateGlobalCheckpointOnReplica(3L, "test");
// index #5 -> force NoOp #4.
orgReplica.applyIndexOperationOnReplica(5, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false,
SourceToParse.source(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON));
new SourceToParse(indexName, "type", "id-5", new BytesArray("{}"), XContentType.JSON));
if (randomBoolean()) {
if (randomBoolean()) {
@ -312,7 +312,7 @@ public class RecoveryTests extends ESIndexLevelReplicationTestCase {
long globalCheckpoint = 0;
for (int i = 0; i < numDocs; i++) {
Engine.IndexResult result = primaryShard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL,
SourceToParse.source(primaryShard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"),
new SourceToParse(primaryShard.shardId().getIndexName(), "_doc", Integer.toString(i), new BytesArray("{}"),
XContentType.JSON),
SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
assertThat(result.getResultType(), equalTo(Engine.Result.Type.SUCCESS));

View File

@ -77,7 +77,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference
.bytes(jsonBuilder()
.startObject()
.startArray("completion")
@ -116,7 +116,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference
.bytes(jsonBuilder()
.startObject()
.startArray("completion")
@ -150,7 +150,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference
.bytes(jsonBuilder()
.startObject()
.startArray("completion")
@ -184,7 +184,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference
.bytes(jsonBuilder()
.startObject()
.startArray("completion")
@ -231,7 +231,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
.endObject();
Exception e = expectThrows(MapperParsingException.class,
() -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON)));
() -> defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON)));
assertEquals("contexts must be a string, number or boolean or a list of string, number or boolean, but was [VALUE_NULL]",
e.getCause().getMessage());
}
@ -252,7 +252,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference
.bytes(jsonBuilder()
.startObject()
.startObject("completion")
@ -284,7 +284,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference
.bytes(jsonBuilder()
.startObject()
.startObject("completion")
@ -327,7 +327,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
.endObject();
Exception e = expectThrows(MapperParsingException.class,
() -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON)));
() -> defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(builder), XContentType.JSON)));
assertEquals("context array must have string, number or boolean values, but was [VALUE_NULL]", e.getCause().getMessage());
}
@ -364,7 +364,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
.endObject()
.endArray()
.endObject();
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", BytesReference.bytes(builder),
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "type1", "1", BytesReference.bytes(builder),
XContentType.JSON));
IndexableField[] fields = parsedDocument.rootDoc().getFields(fieldMapper.name());
assertContextSuggestFields(fields, 3);

View File

@ -63,7 +63,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService();
MappedFieldType completionFieldType = mapperService.fullName("completion");
ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(jsonBuilder()
.startObject()
.startArray("completion")
@ -102,7 +102,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService();
MappedFieldType completionFieldType = mapperService.fullName("completion");
ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(jsonBuilder()
.startObject()
.startArray("completion")
@ -138,7 +138,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService();
MappedFieldType completionFieldType = mapperService.fullName("completion");
ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(jsonBuilder()
.startObject()
.startObject("completion")
@ -195,7 +195,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
.endObject()
.endArray()
.endObject();
ParsedDocument parsedDocument = mapperService.documentMapper().parse(SourceToParse.source("test", "type1", "1",
ParsedDocument parsedDocument = mapperService.documentMapper().parse(new SourceToParse("test", "type1", "1",
BytesReference.bytes(builder), XContentType.JSON));
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertContextSuggestFields(fields, 3);

View File

@ -332,7 +332,7 @@ public abstract class EngineTestCase extends ESTestCase {
source.endObject();
}
source.endObject();
return nestedMapper.parse(SourceToParse.source("test", "type", docId, BytesReference.bytes(source), XContentType.JSON));
return nestedMapper.parse(new SourceToParse("test", "type", docId, BytesReference.bytes(source), XContentType.JSON));
};
}

View File

@ -31,6 +31,7 @@ import org.elasticsearch.index.mapper.DocumentMapperForType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.Mapping;
import org.elasticsearch.index.mapper.RootObjectMapper;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.seqno.SequenceNumbers;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.similarity.SimilarityService;
@ -45,7 +46,6 @@ import java.util.concurrent.atomic.AtomicLong;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.elasticsearch.index.mapper.SourceToParse.source;
public class TranslogHandler implements Engine.TranslogRecoveryRunner {
@ -122,9 +122,8 @@ public class TranslogHandler implements Engine.TranslogRecoveryRunner {
final String indexName = mapperService.index().getName();
final Engine.Index engineIndex = IndexShard.prepareIndex(docMapper(index.type()),
mapperService.getIndexSettings().getIndexVersionCreated(),
source(indexName, index.type(), index.id(), index.source(),
XContentHelper.xContentType(index.source()))
.routing(index.routing()), index.seqNo(), index.primaryTerm(),
new SourceToParse(indexName, index.type(), index.id(), index.source(), XContentHelper.xContentType(index.source()),
index.routing()), index.seqNo(), index.primaryTerm(),
index.version(), null, origin, index.getAutoGeneratedIdTimestamp(), true, SequenceNumbers.UNASSIGNED_SEQ_NO, 0);
return engineIndex;
case DELETE:

View File

@ -697,8 +697,8 @@ public abstract class IndexShardTestCase extends ESTestCase {
protected Engine.IndexResult indexDoc(IndexShard shard, String type, String id, String source, XContentType xContentType,
String routing)
throws IOException {
SourceToParse sourceToParse = SourceToParse.source(shard.shardId().getIndexName(), type, id, new BytesArray(source), xContentType);
sourceToParse.routing(routing);
SourceToParse sourceToParse = new SourceToParse(
shard.shardId().getIndexName(), type, id, new BytesArray(source), xContentType, routing);
Engine.IndexResult result;
if (shard.routingEntry().primary()) {
result = shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, sourceToParse,

View File

@ -39,13 +39,13 @@ public class FollowEngineIndexShardTests extends IndexShardTestCase {
long seqNo = -1;
for (int i = 0; i < 8; i++) {
final String id = Long.toString(i);
SourceToParse sourceToParse = SourceToParse.source(indexShard.shardId().getIndexName(), "_doc", id,
SourceToParse sourceToParse = new SourceToParse(indexShard.shardId().getIndexName(), "_doc", id,
new BytesArray("{}"), XContentType.JSON);
indexShard.applyIndexOperationOnReplica(++seqNo, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse);
}
long seqNoBeforeGap = seqNo;
seqNo += 8;
SourceToParse sourceToParse = SourceToParse.source(indexShard.shardId().getIndexName(), "_doc", "9",
SourceToParse sourceToParse = new SourceToParse(indexShard.shardId().getIndexName(), "_doc", "9",
new BytesArray("{}"), XContentType.JSON);
indexShard.applyIndexOperationOnReplica(seqNo, 1, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse);

View File

@ -46,6 +46,7 @@ import org.elasticsearch.index.engine.InternalEngineFactory;
import org.elasticsearch.index.fieldvisitor.FieldsVisitor;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.SeqNoFieldMapper;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.seqno.SeqNoStats;
import org.elasticsearch.index.seqno.SequenceNumbers;
@ -67,8 +68,6 @@ import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import static org.elasticsearch.index.mapper.SourceToParse.source;
public class SourceOnlySnapshotShardTests extends IndexShardTestCase {
public void testSourceIncomplete() throws IOException {
@ -293,9 +292,9 @@ public class SourceOnlySnapshotShardTests extends IndexShardTestCase {
Uid uid = rootFieldsVisitor.uid();
BytesReference source = rootFieldsVisitor.source();
assert source != null : "_source is null but should have been filtered out at snapshot time";
Engine.Result result = targetShard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, source
(index, uid.type(), uid.id(), source, XContentHelper.xContentType(source))
.routing(rootFieldsVisitor.routing()), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, 1, false);
Engine.Result result = targetShard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL,
new SourceToParse(index, uid.type(), uid.id(), source, XContentHelper.xContentType(source),
rootFieldsVisitor.routing()), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, 1, false);
if (result.getResultType() != Engine.Result.Type.SUCCESS) {
throw new IllegalStateException("failed applying post restore operation result: " + result
.getResultType(), result.getFailure());