Remove DocumentMapper#parse(String index, String type, String id, BytesReference source) (#23706)
Removed `parse(String index, String type, String id, BytesReference source)` in DocumentMapper.java and replaced all of its use in Test files with `parse(SourceToParse source)`. `parse(String index, String type, String id, BytesReference source)` was only used in test files and never in the main code so it was removed. All of the test files that used it was then modified to use `parse(SourceToParse source)` method that existing in DocumentMapper.java
This commit is contained in:
parent
6577503b37
commit
63757efe9c
|
@ -257,11 +257,6 @@ public class DocumentMapper implements ToXContent {
|
|||
return this.objectMappers;
|
||||
}
|
||||
|
||||
// TODO this method looks like it is only used in tests...
|
||||
public ParsedDocument parse(String index, String type, String id, BytesReference source) throws MapperParsingException {
|
||||
return parse(SourceToParse.source(index, type, id, source, XContentType.JSON));
|
||||
}
|
||||
|
||||
public ParsedDocument parse(SourceToParse source) throws MapperParsingException {
|
||||
return documentParser.parseDocument(source);
|
||||
}
|
||||
|
|
|
@ -27,8 +27,10 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
import org.elasticsearch.index.mapper.SourceToParse;
|
||||
|
||||
import java.util.List;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -56,16 +58,17 @@ public class BinaryDVFieldDataTests extends AbstractFieldDataTestCase {
|
|||
bytesList1.add(randomBytes());
|
||||
bytesList1.add(randomBytes());
|
||||
XContentBuilder doc = XContentFactory.jsonBuilder().startObject().startArray("field").value(bytesList1.get(0)).value(bytesList1.get(1)).endArray().endObject();
|
||||
ParsedDocument d = mapper.parse("test", "test", "1", doc.bytes());
|
||||
ParsedDocument d = mapper.parse(SourceToParse.source("test", "test", "1",
|
||||
doc.bytes(), XContentType.JSON));
|
||||
writer.addDocument(d.rootDoc());
|
||||
|
||||
byte[] bytes1 = randomBytes();
|
||||
doc = XContentFactory.jsonBuilder().startObject().field("field", bytes1).endObject();
|
||||
d = mapper.parse("test", "test", "2", doc.bytes());
|
||||
d = mapper.parse(SourceToParse.source("test", "test", "2", doc.bytes(), XContentType.JSON));
|
||||
writer.addDocument(d.rootDoc());
|
||||
|
||||
doc = XContentFactory.jsonBuilder().startObject().endObject();
|
||||
d = mapper.parse("test", "test", "3", doc.bytes());
|
||||
d = mapper.parse(SourceToParse.source("test", "test", "3", doc.bytes(), XContentType.JSON));
|
||||
writer.addDocument(d.rootDoc());
|
||||
|
||||
// test remove duplicate value
|
||||
|
@ -73,7 +76,7 @@ public class BinaryDVFieldDataTests extends AbstractFieldDataTestCase {
|
|||
bytesList2.add(randomBytes());
|
||||
bytesList2.add(randomBytes());
|
||||
doc = XContentFactory.jsonBuilder().startObject().startArray("field").value(bytesList2.get(0)).value(bytesList2.get(1)).value(bytesList2.get(0)).endArray().endObject();
|
||||
d = mapper.parse("test", "test", "4", doc.bytes());
|
||||
d = mapper.parse(SourceToParse.source("test", "test", "4", doc.bytes(), XContentType.JSON));
|
||||
writer.addDocument(d.rootDoc());
|
||||
|
||||
List<LeafReaderContext> readers = refreshReader();
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
@ -92,7 +93,9 @@ public class BinaryFieldMapperTests extends ESSingleNodeTestCase {
|
|||
assertTrue(CompressorFactory.isCompressed(new BytesArray(binaryValue2)));
|
||||
|
||||
for (byte[] value : Arrays.asList(binaryValue1, binaryValue2)) {
|
||||
ParsedDocument doc = mapper.parse("test", "type", "id", XContentFactory.jsonBuilder().startObject().field("field", value).endObject().bytes());
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "id",
|
||||
XContentFactory.jsonBuilder().startObject().field("field", value).endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
BytesRef indexedValue = doc.rootDoc().getBinaryValue("field");
|
||||
assertEquals(new BytesRef(value), indexedValue);
|
||||
FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper("field");
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.ParseContext.Document;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
@ -80,11 +81,12 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", true)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
try (Directory dir = new RAMDirectory();
|
||||
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random())))) {
|
||||
|
@ -150,12 +152,13 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
|
|||
String falsy = randomFrom("false", "off", "no", "0");
|
||||
String truthy = randomFrom("true", "on", "yes", "1");
|
||||
|
||||
ParsedDocument parsedDoc = defaultMapper.parse("legacy", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument parsedDoc = defaultMapper.parse(SourceToParse.source("legacy", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", falsy)
|
||||
.field("field2", truthy)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
Document doc = parsedDoc.rootDoc();
|
||||
assertEquals("F", doc.getField("field1").stringValue());
|
||||
assertEquals("T", doc.getField("field2").stringValue());
|
||||
|
@ -190,7 +193,8 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
|
|||
// omit "false"/"true" here as they should still be parsed correctly
|
||||
.field("field", randomFrom("off", "no", "0", "on", "yes", "1"))
|
||||
.endObject().bytes();
|
||||
MapperParsingException ex = expectThrows(MapperParsingException.class, () -> defaultMapper.parse("test", "type", "1", source));
|
||||
MapperParsingException ex = expectThrows(MapperParsingException.class,
|
||||
() -> defaultMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)));
|
||||
assertEquals("failed to parse [field]", ex.getMessage());
|
||||
}
|
||||
|
||||
|
@ -213,7 +217,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject()
|
||||
.field("field", false)
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", source);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON));
|
||||
assertNotNull(doc.rootDoc().getField("field.as_string"));
|
||||
}
|
||||
|
||||
|
@ -236,13 +240,14 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument parsedDoc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument parsedDoc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("bool1", true)
|
||||
.field("bool2", true)
|
||||
.field("bool3", true)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
Document doc = parsedDoc.rootDoc();
|
||||
IndexableField[] fields = doc.getFields("bool1");
|
||||
assertEquals(2, fields.length);
|
||||
|
|
|
@ -35,9 +35,10 @@ 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("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
.field("thisIsCamelCase", "value1")
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertNotNull(doc.dynamicMappingsUpdate());
|
||||
client().admin().indices().preparePutMapping("test").setType("type")
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.elasticsearch.common.unit.Fuzziness;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
||||
|
@ -152,11 +153,12 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("completion", "suggestion")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertSuggestFields(fields, 1);
|
||||
}
|
||||
|
@ -171,11 +173,12 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.array("completion", "suggestion1", "suggestion2")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertSuggestFields(fields, 2);
|
||||
}
|
||||
|
@ -190,14 +193,15 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("completion")
|
||||
.field("input", "suggestion")
|
||||
.field("weight", 2)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertSuggestFields(fields, 1);
|
||||
}
|
||||
|
@ -212,14 +216,15 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("completion")
|
||||
.array("input", "suggestion1", "suggestion2", "suggestion3")
|
||||
.field("weight", 2)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertSuggestFields(fields, 3);
|
||||
}
|
||||
|
@ -234,7 +239,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("completion")
|
||||
.startObject()
|
||||
|
@ -251,7 +256,8 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertSuggestFields(fields, 3);
|
||||
}
|
||||
|
@ -266,7 +272,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("completion")
|
||||
.startObject()
|
||||
|
@ -283,7 +289,8 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertSuggestFields(fields, 6);
|
||||
}
|
||||
|
@ -297,7 +304,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
try {
|
||||
defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field1")
|
||||
.field("input", "suggestion1")
|
||||
|
@ -307,7 +314,8 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.field("weight", 3)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
fail("Supplying contexts to a non context-enabled field should error");
|
||||
} catch (MapperParsingException e) {
|
||||
assertThat(e.getRootCause().getMessage(), containsString("field1"));
|
||||
|
@ -326,11 +334,12 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
charsRefBuilder.append("sugg");
|
||||
charsRefBuilder.setCharAt(2, '\u001F');
|
||||
try {
|
||||
defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("completion", charsRefBuilder.get().toString())
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
fail("No error indexing value with reserved character [0x1F]");
|
||||
} catch (MapperParsingException e) {
|
||||
Throwable cause = e.unwrapCause().getCause();
|
||||
|
@ -340,11 +349,12 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
charsRefBuilder.setCharAt(2, '\u0000');
|
||||
try {
|
||||
defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("completion", charsRefBuilder.get().toString())
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
fail("No error indexing value with reserved character [0x0]");
|
||||
} catch (MapperParsingException e) {
|
||||
Throwable cause = e.unwrapCause().getCause();
|
||||
|
@ -354,11 +364,12 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
charsRefBuilder.setCharAt(2, '\u001E');
|
||||
try {
|
||||
defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("completion", charsRefBuilder.get().toString())
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
fail("No error indexing value with reserved character [0x1E]");
|
||||
} catch (MapperParsingException e) {
|
||||
Throwable cause = e.unwrapCause().getCause();
|
||||
|
|
|
@ -94,7 +94,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
.field("int_to_str_test", 42)
|
||||
.endObject().bytes();
|
||||
|
||||
ParsedDocument parsedDoc = docMapper.parse("test", "type1", "1", json);
|
||||
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("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"));
|
||||
|
@ -149,7 +149,8 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject("foo").startObject("bar").field("baz", "zoo").endObject().endObject()
|
||||
.endObject().bytes();
|
||||
|
||||
ParseContext.Document doc = docMapper.parse("test", "type1", "1", json).rootDoc();
|
||||
ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json,
|
||||
XContentType.JSON)).rootDoc();
|
||||
assertThat(doc.getFields("copy_test").length, equalTo(1));
|
||||
assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));
|
||||
|
||||
|
@ -175,7 +176,8 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
.field("new_field", "bar")
|
||||
.endObject().bytes();
|
||||
|
||||
ParseContext.Document doc = docMapper.parse("test", "type1", "1", json).rootDoc();
|
||||
ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json,
|
||||
XContentType.JSON)).rootDoc();
|
||||
assertThat(doc.getFields("copy_test").length, equalTo(1));
|
||||
assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));
|
||||
|
||||
|
@ -211,7 +213,8 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
.field("new_field", "bar")
|
||||
.endObject().bytes();
|
||||
|
||||
ParseContext.Document doc = docMapper.parse("test", "type1", "1", json).rootDoc();
|
||||
ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json,
|
||||
XContentType.JSON)).rootDoc();
|
||||
assertThat(doc.getFields("copy_test").length, equalTo(1));
|
||||
assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));
|
||||
|
||||
|
@ -240,7 +243,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().bytes();
|
||||
|
||||
try {
|
||||
docMapper.parse("test", "type1", "1", json).rootDoc();
|
||||
docMapper.parse(SourceToParse.source("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"));
|
||||
|
@ -274,7 +277,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().bytes();
|
||||
|
||||
try {
|
||||
docMapper.parse("test", "type1", "1", json).rootDoc();
|
||||
docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc();
|
||||
fail();
|
||||
} catch (MapperParsingException ex) {
|
||||
assertThat(ex.getMessage(), startsWith("mapping set to strict, dynamic introduction of [field] within [very.far] is not allowed"));
|
||||
|
@ -377,7 +380,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
.endArray()
|
||||
.endObject();
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", jsonDoc.bytes());
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", jsonDoc.bytes(), XContentType.JSON));
|
||||
assertEquals(6, doc.docs().size());
|
||||
|
||||
Document nested = doc.docs().get(0);
|
||||
|
@ -439,7 +442,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().bytes();
|
||||
|
||||
try {
|
||||
docMapper.parse("test", "type1", "1", json).rootDoc();
|
||||
docMapper.parse(SourceToParse.source("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`"));
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.index.DocValuesType;
|
|||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
@ -62,11 +63,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "2016-03-11")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -90,11 +92,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "2016-03-11")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -111,11 +114,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "2016-03-11")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -132,11 +136,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "2016-03-11")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(3, fields.length);
|
||||
|
@ -158,11 +163,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ThrowingRunnable runnable = () -> mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "2016-03-99")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
||||
assertThat(e.getCause().getMessage(), containsString("Cannot parse \"2016-03-99\""));
|
||||
|
||||
|
@ -173,11 +179,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", ":1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(0, fields.length);
|
||||
|
@ -193,11 +200,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 1457654400)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -214,11 +222,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 1457654400)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
}
|
||||
|
||||
public void testNullValue() throws IOException {
|
||||
|
@ -234,11 +243,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
|
||||
|
||||
mapping = XContentFactory.jsonBuilder().startObject()
|
||||
|
@ -254,11 +264,12 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
|
|||
mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
IndexableField pointField = fields[0];
|
||||
|
@ -322,11 +333,12 @@ 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("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", DateTimeFormat.forPattern(timeZonePattern).print(randomDate))
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
||||
import org.elasticsearch.index.mapper.DocumentFieldMappers;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
|
@ -167,7 +168,11 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase {
|
|||
barrier.await();
|
||||
for (int i = 0; i < 200 && stopped.get() == false; i++) {
|
||||
final String fieldName = Integer.toString(i);
|
||||
ParsedDocument doc = documentMapper.parse("test", "test", fieldName, new BytesArray("{ \"" + fieldName + "\" : \"test\" }"));
|
||||
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test",
|
||||
"test",
|
||||
fieldName,
|
||||
new BytesArray("{ \"" + fieldName + "\" : \"test\" }"),
|
||||
XContentType.JSON));
|
||||
Mapping update = doc.dynamicMappingsUpdate();
|
||||
assert update != null;
|
||||
lastIntroducedFieldName.set(fieldName);
|
||||
|
@ -186,7 +191,11 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase {
|
|||
while(stopped.get() == false) {
|
||||
final String fieldName = lastIntroducedFieldName.get();
|
||||
final BytesReference source = new BytesArray("{ \"" + fieldName + "\" : \"test\" }");
|
||||
ParsedDocument parsedDoc = documentMapper.parse("test", "test", "random", source);
|
||||
ParsedDocument parsedDoc = documentMapper.parse(SourceToParse.source("test",
|
||||
"test",
|
||||
"random",
|
||||
source,
|
||||
XContentType.JSON));
|
||||
if (parsedDoc.dynamicMappingsUpdate() != null) {
|
||||
// not in the mapping yet, try again
|
||||
continue;
|
||||
|
|
|
@ -71,7 +71,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo")
|
||||
.field("field", "1234")
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertNull(doc.rootDoc().getField("field"));
|
||||
assertNotNull(doc.rootDoc().getField(UidFieldMapper.NAME));
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.field("foo", "1234")
|
||||
.field("bar", 10)
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertNull(doc.rootDoc().getField("foo"));
|
||||
assertNotNull(doc.rootDoc().getField("bar"));
|
||||
assertNotNull(doc.rootDoc().getField(UidFieldMapper.NAME));
|
||||
|
@ -114,7 +114,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.field("baz", 789)
|
||||
.endObject()
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertNull(doc.dynamicMappingsUpdate()); // no update!
|
||||
String[] values = doc.rootDoc().getValues("foo.bar.baz");
|
||||
assertEquals(3, values.length);
|
||||
|
@ -136,7 +136,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.field("foo.bar", 123)
|
||||
.endObject().bytes();
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("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());
|
||||
|
@ -162,7 +162,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.field("foo.bar",42)
|
||||
.endObject().bytes();
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("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());
|
||||
|
@ -183,7 +183,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo")
|
||||
.field("bar", "something")
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertNotNull(doc.dynamicMappingsUpdate());
|
||||
assertNotNull(doc.rootDoc().getField("foo.bar"));
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo").startObject("bar")
|
||||
.field("baz", "something")
|
||||
.endObject().endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertNotNull(doc.dynamicMappingsUpdate());
|
||||
assertNotNull(doc.rootDoc().getField("foo.bar.baz"));
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo")
|
||||
.field("bar", "something")
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertNull(doc.dynamicMappingsUpdate());
|
||||
assertNull(doc.rootDoc().getField("foo.bar"));
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startArray().value(0).value(0).endArray()
|
||||
.startArray().value(1).value(1).endArray()
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(2, doc.rootDoc().getFields("foo").length);
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(0)
|
||||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(4, doc.rootDoc().getFields("foo").length);
|
||||
}
|
||||
|
||||
|
@ -383,7 +383,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(0)
|
||||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(4, doc.rootDoc().getFields("foo").length);
|
||||
}
|
||||
|
||||
|
@ -398,7 +398,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(0)
|
||||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(0, doc.rootDoc().getFields("foo").length);
|
||||
}
|
||||
|
||||
|
@ -414,7 +414,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
||||
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startArray().value(0).value(0).endArray()
|
||||
.startArray().value(1).value(1).endArray()
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("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().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(4, doc.rootDoc().getFields("foo").length);
|
||||
}
|
||||
|
||||
|
@ -464,7 +464,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo")
|
||||
.field("bar", "baz")
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(2, doc.rootDoc().getFields("foo.bar").length);
|
||||
}
|
||||
|
||||
|
@ -478,7 +478,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo")
|
||||
.field("bar", "baz")
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(0, doc.rootDoc().getFields("foo.bar").length);
|
||||
}
|
||||
|
||||
|
@ -493,7 +493,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.field("bar", "baz")
|
||||
.endObject().endObject().bytes();
|
||||
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
||||
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -507,7 +507,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject()
|
||||
.field("bar", "baz")
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(0, doc.rootDoc().getFields("bar").length);
|
||||
}
|
||||
|
||||
|
@ -522,7 +522,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.field("bar", "baz")
|
||||
.endObject().bytes();
|
||||
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
||||
assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -536,7 +536,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject()
|
||||
.field("bar", (String) null)
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(0, doc.rootDoc().getFields("bar").length);
|
||||
}
|
||||
|
||||
|
@ -551,7 +551,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.field("bar", (String) null)
|
||||
.endObject().bytes();
|
||||
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
||||
assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -565,7 +565,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject().field("foo", (Long) null)
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(0, doc.rootDoc().getFields("foo").length);
|
||||
}
|
||||
|
||||
|
@ -580,7 +580,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(0)
|
||||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length);
|
||||
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
|
||||
assertNotNull(fooMapper);
|
||||
|
@ -607,7 +607,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(0)
|
||||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length);
|
||||
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
|
||||
assertNotNull(fooMapper);
|
||||
|
@ -633,7 +633,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(0)
|
||||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length);
|
||||
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
|
||||
assertNotNull(fooMapper);
|
||||
|
@ -659,7 +659,8 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(0)
|
||||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
MapperParsingException exception = expectThrows(MapperParsingException.class, () -> mapper.parse("test", "type", "1", bytes));
|
||||
MapperParsingException exception = expectThrows(MapperParsingException.class,
|
||||
() -> mapper.parse(SourceToParse.source("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());
|
||||
}
|
||||
|
@ -675,7 +676,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(0)
|
||||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length);
|
||||
}
|
||||
|
||||
|
@ -691,7 +692,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.value(1)
|
||||
.endArray().endObject().bytes();
|
||||
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
||||
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -704,7 +705,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject().field("foo.bar.baz", 0)
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length);
|
||||
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
|
||||
assertNotNull(fooMapper);
|
||||
|
@ -729,7 +730,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject().field("foo.bar.baz", 0)
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length);
|
||||
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
|
||||
assertNotNull(fooMapper);
|
||||
|
@ -753,7 +754,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject().field("foo.bar.baz", 0)
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length);
|
||||
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
|
||||
assertNotNull(fooMapper);
|
||||
|
@ -777,7 +778,8 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject().field("foo.bar.baz", 0)
|
||||
.endObject().bytes();
|
||||
MapperParsingException exception = expectThrows(MapperParsingException.class, () -> mapper.parse("test", "type", "1", bytes));
|
||||
MapperParsingException exception = expectThrows(MapperParsingException.class,
|
||||
() -> mapper.parse(SourceToParse.source("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());
|
||||
}
|
||||
|
@ -791,7 +793,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject().field("foo.bar.baz", 0)
|
||||
.endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length);
|
||||
}
|
||||
|
||||
|
@ -805,7 +807,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().field("foo.bar.baz", 0)
|
||||
.endObject().bytes();
|
||||
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
||||
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -819,7 +821,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo.bar.baz")
|
||||
.field("a", 0)
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("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);
|
||||
|
@ -848,7 +850,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo.bar.baz")
|
||||
.field("a", 0)
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("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);
|
||||
|
@ -872,7 +874,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz").field("a", 0).endObject().endObject()
|
||||
.bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("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);
|
||||
|
@ -898,7 +900,9 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz").field("a", 0).endObject().endObject()
|
||||
.bytes();
|
||||
MapperParsingException exception = expectThrows(MapperParsingException.class, () -> mapper.parse("test", "type", "1", bytes));
|
||||
MapperParsingException exception = expectThrows(MapperParsingException.class,
|
||||
() -> mapper.parse(SourceToParse.source("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());
|
||||
}
|
||||
|
@ -913,7 +917,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.startObject().startObject("foo.bar.baz")
|
||||
.field("a", 0)
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
assertEquals(0, doc.rootDoc().getFields("foo.bar.baz.a").length);
|
||||
}
|
||||
|
||||
|
@ -928,7 +932,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.field("a", 0)
|
||||
.endObject().endObject().bytes();
|
||||
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class,
|
||||
() -> mapper.parse("test", "type", "1", bytes));
|
||||
() -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
||||
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -939,12 +943,11 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
BytesReference bytes = XContentFactory.jsonBuilder().startObject().field("_ttl", 0).endObject().bytes();
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, () ->
|
||||
mapper.parse("test", "type", "1", bytes)
|
||||
);
|
||||
mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("cannot be added inside a document"));
|
||||
|
||||
BytesReference bytes2 = XContentFactory.jsonBuilder().startObject().field("foo._ttl", 0).endObject().bytes();
|
||||
mapper.parse("test", "type", "1", bytes2); // parses without error
|
||||
mapper.parse(SourceToParse.source("test", "type", "1", bytes2, XContentType.JSON)); // parses without error
|
||||
}
|
||||
|
||||
public void testSimpleMapper() throws Exception {
|
||||
|
@ -955,10 +958,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("test", "person", "1", json).rootDoc();
|
||||
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
|
||||
assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
|
||||
doc = docMapper.parse("test", "person", "1", json).rootDoc();
|
||||
doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
}
|
||||
|
||||
public void testParseToJsonAndParse() throws Exception {
|
||||
|
@ -969,7 +972,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("test", "person", "1", json).rootDoc();
|
||||
Document doc = builtDocMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
assertThat(doc.get(docMapper.uidMapper().fieldType().name()), equalTo(Uid.createUid("person", "1")));
|
||||
assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
|
||||
}
|
||||
|
@ -981,7 +984,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("test", "person", "1", json).rootDoc();
|
||||
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
assertThat(doc.get(docMapper.uidMapper().fieldType().name()), equalTo(Uid.createUid("person", "1")));
|
||||
assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
|
||||
}
|
||||
|
@ -990,7 +993,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
|
||||
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("test", "person", "1", json).rootDoc();
|
||||
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
assertThat(doc.get(docMapper.uidMapper().fieldType().name()), equalTo(Uid.createUid("person", "1")));
|
||||
assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
|
||||
}
|
||||
|
@ -1016,7 +1019,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
BytesReference json = new BytesArray("".getBytes(StandardCharsets.UTF_8));
|
||||
try {
|
||||
docMapper.parse("test", "person", "1", json).rootDoc();
|
||||
docMapper.parse(SourceToParse.source("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"));
|
||||
|
@ -1028,13 +1031,14 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("test1", "value1")
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("test1"), equalTo("value1"));
|
||||
assertThat(doc.rootDoc().get("test2"), equalTo("value2"));
|
||||
|
@ -1046,13 +1050,14 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject().startObject("type")
|
||||
.field("test1", "value1")
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject().endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
|
||||
assertThat(doc.rootDoc().get("type.test2"), equalTo("value2"));
|
||||
|
@ -1064,14 +1069,15 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "value_type")
|
||||
.field("test1", "value1")
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("type"), equalTo("value_type"));
|
||||
assertThat(doc.rootDoc().get("test1"), equalTo("value1"));
|
||||
|
@ -1084,14 +1090,15 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject().startObject("type")
|
||||
.field("type", "value_type")
|
||||
.field("test1", "value1")
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject().endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("type.type"), equalTo("value_type"));
|
||||
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
|
||||
|
@ -1104,14 +1111,15 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("type").field("type_field", "type_value").endObject()
|
||||
.field("test1", "value1")
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
// in this case, we analyze the type object as the actual document, and ignore the other same level fields
|
||||
assertThat(doc.rootDoc().get("type.type_field"), equalTo("type_value"));
|
||||
|
@ -1124,14 +1132,15 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject().startObject("type")
|
||||
.startObject("type").field("type_field", "type_value").endObject()
|
||||
.field("test1", "value1")
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject().endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("type.type.type_field"), equalTo("type_value"));
|
||||
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
|
||||
|
@ -1144,14 +1153,15 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject().startObject("type")
|
||||
.field("test1", "value1")
|
||||
.field("test2", "value2")
|
||||
.field("type", "value_type")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject().endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("type.type"), equalTo("value_type"));
|
||||
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
|
||||
|
@ -1164,14 +1174,15 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject().startObject("type")
|
||||
.field("test1", "value1")
|
||||
.field("type", "value_type")
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject().endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("type.type"), equalTo("value_type"));
|
||||
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
|
||||
|
@ -1184,14 +1195,15 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("test1", "value1")
|
||||
.startObject("type").field("type_field", "type_value").endObject()
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
// when the type is not the first one, we don't confuse it...
|
||||
assertThat(doc.rootDoc().get("type.type_field"), equalTo("type_value"));
|
||||
|
@ -1205,14 +1217,15 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject().startObject("type")
|
||||
.field("test1", "value1")
|
||||
.startObject("type").field("type_field", "type_value").endObject()
|
||||
.field("test2", "value2")
|
||||
.startObject("inner").field("inner_field", "inner_value").endObject()
|
||||
.endObject().endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("type.type.type_field"), equalTo("type_value"));
|
||||
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
|
||||
|
@ -1235,7 +1248,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("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
Mapping update = doc.dynamicMappingsUpdate();
|
||||
assertNotNull(update);
|
||||
Mapper dateMapper = update.root().getMapper("foo");
|
||||
|
@ -1257,7 +1270,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
.endObject().bytes();
|
||||
|
||||
// We should have generated a date field
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON));
|
||||
Mapping update = doc.dynamicMappingsUpdate();
|
||||
assertNotNull(update);
|
||||
Mapper dateMapper = update.root().getMapper("foo");
|
||||
|
|
|
@ -48,7 +48,7 @@ public class DoubleIndexingDocTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper mapper = index.mapperService().documentMapper("type");
|
||||
QueryShardContext context = index.newQueryShardContext(0, null, () -> 0L);
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", "value1")
|
||||
.field("field2", 1)
|
||||
|
@ -56,7 +56,8 @@ public class DoubleIndexingDocTests extends ESSingleNodeTestCase {
|
|||
.field("field4", "2010-01-01")
|
||||
.startArray("field5").value(1).value(2).value(3).endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertNotNull(doc.dynamicMappingsUpdate());
|
||||
client().admin().indices().preparePutMapping("test").setType("type")
|
||||
.setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
|
||||
|
|
|
@ -58,12 +58,13 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", "value1")
|
||||
.field("field2", "value2")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("field1"), equalTo("value1"));
|
||||
assertThat(doc.rootDoc().get("field2"), equalTo("value2"));
|
||||
|
@ -79,12 +80,13 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", "value1")
|
||||
.field("field2", "value2")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("field1"), equalTo("value1"));
|
||||
assertThat(doc.rootDoc().get("field2"), nullValue());
|
||||
|
@ -101,20 +103,22 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse("test", "type", "1", jsonBuilder()
|
||||
StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", "value1")
|
||||
.field("field2", "value2")
|
||||
.endObject()
|
||||
.bytes()));
|
||||
.bytes(),
|
||||
XContentType.JSON)));
|
||||
assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed"));
|
||||
|
||||
e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", "value1")
|
||||
.field("field2", (String) null)
|
||||
.endObject()
|
||||
.bytes()));
|
||||
.bytes(),
|
||||
XContentType.JSON)));
|
||||
assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed"));
|
||||
}
|
||||
|
||||
|
@ -130,13 +134,14 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", jsonBuilder()
|
||||
.startObject().startObject("obj1")
|
||||
.field("field1", "value1")
|
||||
.field("field2", "value2")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("obj1.field1"), equalTo("value1"));
|
||||
assertThat(doc.rootDoc().get("obj1.field2"), nullValue());
|
||||
|
@ -155,13 +160,14 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () ->
|
||||
defaultMapper.parse("test", "type", "1", jsonBuilder()
|
||||
defaultMapper.parse(SourceToParse.source("test", "type", "1", jsonBuilder()
|
||||
.startObject().startObject("obj1")
|
||||
.field("field1", "value1")
|
||||
.field("field2", "value2")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes()));
|
||||
.bytes(),
|
||||
XContentType.JSON)));
|
||||
assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [obj1] is not allowed"));
|
||||
}
|
||||
|
||||
|
@ -585,7 +591,8 @@ 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().bytes();
|
||||
ParsedDocument parsedDocument = mapper.parse("index", "type", "id", source);
|
||||
ParsedDocument parsedDocument = mapper.parse(SourceToParse.source("index", "type", "id", source,
|
||||
XContentType.JSON));
|
||||
Mapping update = parsedDocument.dynamicMappingsUpdate();
|
||||
assertNotNull(update);
|
||||
assertThat(((FieldMapper) update.root().getMapper("foo")).fieldType().typeName(), equalTo("float"));
|
||||
|
@ -603,12 +610,13 @@ 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("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("s_long", "100")
|
||||
.field("s_double", "100.0")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertNotNull(doc.dynamicMappingsUpdate());
|
||||
client().admin().indices().preparePutMapping("test").setType("type")
|
||||
.setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
|
||||
|
@ -629,12 +637,13 @@ 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("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("s_long", "100")
|
||||
.field("s_double", "100.0")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertNotNull(doc.dynamicMappingsUpdate());
|
||||
assertAcked(client().admin().indices().preparePutMapping("test").setType("type")
|
||||
.setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get());
|
||||
|
@ -677,13 +686,14 @@ 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("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("date1", "2016-11-20")
|
||||
.field("date2", "2016-11-20")
|
||||
.field("date3", "2016-11-20")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertNotNull(doc.dynamicMappingsUpdate());
|
||||
assertAcked(client().admin().indices().preparePutMapping("test").setType("type")
|
||||
.setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get());
|
||||
|
|
|
@ -51,7 +51,8 @@ public class DynamicTemplatesTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper docMapper = index.mapperService().documentMapper("person");
|
||||
builder = JsonXContent.contentBuilder();
|
||||
builder.startObject().field("s", "hello").field("l", 1).endObject();
|
||||
ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", builder.bytes());
|
||||
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", builder.bytes(),
|
||||
XContentType.JSON));
|
||||
client().admin().indices().preparePutMapping("test").setType("person")
|
||||
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
|
||||
|
||||
|
@ -73,7 +74,8 @@ 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("test", "person", "1", new BytesArray(json));
|
||||
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json),
|
||||
XContentType.JSON));
|
||||
client().admin().indices().preparePutMapping("test").setType("person")
|
||||
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
|
||||
docMapper = index.mapperService().documentMapper("person");
|
||||
|
@ -131,7 +133,8 @@ 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("test", "person", "1", new BytesArray(json));
|
||||
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json),
|
||||
XContentType.JSON));
|
||||
client().admin().indices().preparePutMapping("test").setType("person")
|
||||
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
|
||||
docMapper = index.mapperService().documentMapper("person");
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.compress.CompressedXContent;
|
|||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.indices.mapper.MapperRegistry;
|
||||
|
@ -76,11 +77,12 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().endObject().string()
|
||||
));
|
||||
|
||||
ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("field.bool"), notNullValue());
|
||||
assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T"));
|
||||
|
@ -136,11 +138,12 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().endObject().endObject()
|
||||
.string()));
|
||||
|
||||
ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("field.bool"), notNullValue());
|
||||
assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T"));
|
||||
|
@ -204,11 +207,12 @@ public class ExternalFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().endObject().endObject()
|
||||
.string()));
|
||||
|
||||
ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("field.bool"), notNullValue());
|
||||
assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T"));
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.indices.IndicesModule;
|
||||
|
@ -88,14 +89,15 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
|
|||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("a", "100")
|
||||
.startObject("b")
|
||||
.field("c", 42)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertFieldNames(set("a", "a.keyword", "b", "b.c", "_uid", "_type", "_version", "_seq_no", "_primary_term", "_source"), doc);
|
||||
}
|
||||
|
@ -108,11 +110,12 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
|
|||
FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class);
|
||||
assertTrue(fieldNamesMapper.fieldType().isEnabled());
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertFieldNames(set("field", "field.keyword", "_uid", "_type", "_version", "_seq_no", "_primary_term", "_source"), doc);
|
||||
}
|
||||
|
@ -125,11 +128,12 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
|
|||
FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class);
|
||||
assertFalse(fieldNamesMapper.fieldType().isEnabled());
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertNull(doc.rootDoc().get("_field_names"));
|
||||
}
|
||||
|
@ -244,7 +248,8 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
|
|||
queryShardContext);
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
|
||||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
ParsedDocument parsedDocument = mapper.parse("index", "type", "id", new BytesArray("{}"));
|
||||
ParsedDocument parsedDocument = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(FieldNamesFieldMapper.NAME);
|
||||
boolean found = false;
|
||||
for (IndexableField f : fields) {
|
||||
|
|
|
@ -40,7 +40,8 @@ public class GenericStoreDynamicTemplateTests 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/genericstore/test-data.json");
|
||||
ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json));
|
||||
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json),
|
||||
XContentType.JSON));
|
||||
client().admin().indices().preparePutMapping("test").setType("person")
|
||||
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
|
||||
docMapper = index.mapperService().documentMapper("person");
|
||||
|
|
|
@ -55,11 +55,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
String mapping = xContentBuilder.endObject().endObject().endObject().endObject().string();
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("point", stringEncode(1.3, 1.2))
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("point"), notNullValue());
|
||||
}
|
||||
|
@ -70,11 +71,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
String mapping = xContentBuilder.field("store", true).endObject().endObject().endObject().endObject().string();
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("point").field("lat", 1.2).field("lon", 1.3).endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("point"), notNullValue());
|
||||
}
|
||||
|
@ -85,14 +87,15 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
String mapping = xContentBuilder.field("store", true).endObject().endObject().endObject().endObject().string();
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point")
|
||||
.startObject().field("lat", 1.2).field("lon", 1.3).endObject()
|
||||
.startObject().field("lat", 1.4).field("lon", 1.5).endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
// doc values are enabled by default, but in this test we disable them; we should only have 2 points
|
||||
assertThat(doc.rootDoc().getFields("point"), notNullValue());
|
||||
|
@ -106,11 +109,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type",
|
||||
new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("point", "1.2,1.3")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("point"), notNullValue());
|
||||
}
|
||||
|
@ -122,11 +126,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type",
|
||||
new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("point", "1.2,1.3")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertThat(doc.rootDoc().getField("point"), notNullValue());
|
||||
}
|
||||
|
||||
|
@ -137,14 +142,15 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type",
|
||||
new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point")
|
||||
.value("1.2,1.3")
|
||||
.value("1.4,1.5")
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
// doc values are enabled by default, but in this test we disable them; we should only have 2 points
|
||||
assertThat(doc.rootDoc().getFields("point"), notNullValue());
|
||||
|
@ -157,11 +163,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
String mapping = xContentBuilder.endObject().endObject().endObject().endObject().string();
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point").value(1.3).value(1.2).endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("point"), notNullValue());
|
||||
}
|
||||
|
@ -173,11 +180,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
String mapping = xContentBuilder.endObject().endObject().endObject().endArray().endObject().endObject().string();
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point").value(1.3).value(1.2).endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("point"), notNullValue());
|
||||
}
|
||||
|
@ -188,11 +196,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
String mapping = xContentBuilder.field("store", true).endObject().endObject().endObject().endObject().string();
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point").value(1.3).value(1.2).endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("point"), notNullValue());
|
||||
assertThat(doc.rootDoc().getFields("point").length, equalTo(3));
|
||||
|
@ -205,14 +214,15 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().endObject().string();
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point")
|
||||
.startArray().value(1.3).value(1.2).endArray()
|
||||
.startArray().value(1.5).value(1.4).endArray()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getFields("point"), notNullValue());
|
||||
assertThat(doc.rootDoc().getFields("point").length, CoreMatchers.equalTo(4));
|
||||
|
|
|
@ -40,10 +40,11 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().endObject().string();
|
||||
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get(UidFieldMapper.NAME), notNullValue());
|
||||
assertThat(doc.rootDoc().get(IdFieldMapper.NAME), nullValue());
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
|
@ -50,11 +51,12 @@ public class IndexFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.endObject().endObject().string();
|
||||
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("_index"), nullValue());
|
||||
assertThat(doc.rootDoc().get("field"), equalTo("value"));
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.elasticsearch.common.network.InetAddresses;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
@ -65,11 +66,12 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "::1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -93,11 +95,12 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "::1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -114,11 +117,12 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "::1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -136,11 +140,12 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "::1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(3, fields.length);
|
||||
|
@ -163,11 +168,12 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ThrowingRunnable runnable = () -> mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", ":1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
||||
assertThat(e.getCause().getMessage(), containsString("':1' is not an IP string literal"));
|
||||
|
||||
|
@ -177,11 +183,12 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", ":1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(0, fields.length);
|
||||
|
@ -200,11 +207,12 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
|
||||
|
||||
mapping = XContentFactory.jsonBuilder().startObject()
|
||||
|
@ -220,11 +228,12 @@ public class IpFieldMapperTests extends ESSingleNodeTestCase {
|
|||
mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
IndexableField pointField = fields[0];
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.index.IndexableField;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.mapper.ParseContext.Document;
|
||||
|
@ -45,7 +46,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase {
|
|||
assertThat(docMapper.mappers().getMapper("name.indexed"), nullValue());
|
||||
|
||||
BytesReference json = XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject().bytes();
|
||||
Document doc = docMapper.parse("test", "person", "1", json).rootDoc();
|
||||
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
IndexableField f = doc.getField("name");
|
||||
assertThat(f, notNullValue());
|
||||
f = doc.getField("name.indexed");
|
||||
|
@ -62,7 +63,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase {
|
|||
assertThat(docMapper.mappers().getMapper("name.not_indexed2"), nullValue());
|
||||
assertThat(docMapper.mappers().getMapper("name.not_indexed3"), nullValue());
|
||||
|
||||
doc = docMapper.parse("test", "person", "1", json).rootDoc();
|
||||
doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
f = doc.getField("name");
|
||||
assertThat(f, notNullValue());
|
||||
f = doc.getField("name.indexed");
|
||||
|
@ -101,7 +102,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase {
|
|||
assertThat(docMapper.mappers().getMapper("name.indexed"), nullValue());
|
||||
|
||||
BytesReference json = XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject().bytes();
|
||||
Document doc = docMapper.parse("test", "person", "1", json).rootDoc();
|
||||
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
IndexableField f = doc.getField("name");
|
||||
assertThat(f, notNullValue());
|
||||
f = doc.getField("name.indexed");
|
||||
|
@ -119,7 +120,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase {
|
|||
assertThat(docMapper.mappers().getMapper("name.not_indexed2"), nullValue());
|
||||
assertThat(docMapper.mappers().getMapper("name.not_indexed3"), nullValue());
|
||||
|
||||
doc = docMapper.parse("test", "person", "1", json).rootDoc();
|
||||
doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
f = doc.getField("name");
|
||||
assertThat(f, notNullValue());
|
||||
f = doc.getField("name.indexed");
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.util.BytesRef;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
@ -70,11 +71,12 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -106,20 +108,22 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "elk")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
||||
doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "elasticsearch")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(0, fields.length);
|
||||
|
@ -133,11 +137,12 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
|
||||
|
||||
mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||
|
@ -148,19 +153,21 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(0, fields.length);
|
||||
|
||||
doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -176,11 +183,12 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -196,11 +204,12 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -217,11 +226,12 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -238,11 +248,12 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -278,11 +289,12 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -299,11 +311,12 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "AbC")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.DateFieldMapper;
|
||||
|
@ -62,7 +63,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
|
|||
private void testMultiField(String mapping) throws Exception {
|
||||
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));
|
||||
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
|
||||
Document doc = docMapper.parse("test", "person", "1", json).rootDoc();
|
||||
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
|
||||
IndexableField f = doc.getField("name");
|
||||
assertThat(f.name(), equalTo("name"));
|
||||
|
@ -146,7 +147,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
|
|||
|
||||
|
||||
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
|
||||
Document doc = docMapper.parse("test", "person", "1", json).rootDoc();
|
||||
Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc();
|
||||
|
||||
IndexableField f = doc.getField("name");
|
||||
assertThat(f.name(), equalTo("name"));
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
||||
import org.elasticsearch.index.mapper.ObjectMapper.Dynamic;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
@ -42,21 +43,23 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.nullField("nested1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(1));
|
||||
|
||||
doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startArray("nested").endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(1));
|
||||
}
|
||||
|
@ -72,12 +75,13 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
|
||||
assertThat(nested1Mapper.nested().isNested(), equalTo(true));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startObject("nested1").field("field1", "1").field("field2", "2").endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(2));
|
||||
assertThat(doc.docs().get(0).get(TypeFieldMapper.NAME), equalTo(nested1Mapper.nestedTypePathAsString()));
|
||||
|
@ -87,7 +91,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
assertThat(doc.docs().get(1).get("field"), equalTo("value"));
|
||||
|
||||
|
||||
doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startArray("nested1")
|
||||
|
@ -95,7 +99,8 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject().field("field1", "3").field("field2", "4").endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(3));
|
||||
assertThat(doc.docs().get(0).get(TypeFieldMapper.NAME), equalTo(nested1Mapper.nestedTypePathAsString()));
|
||||
|
@ -127,7 +132,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false));
|
||||
assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startArray("nested1")
|
||||
|
@ -135,7 +140,8 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject().field("field1", "4").startArray("nested2").startObject().field("field2", "5").endObject().startObject().field("field2", "6").endObject().endArray().endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(7));
|
||||
assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6"));
|
||||
|
@ -178,7 +184,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true));
|
||||
assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startArray("nested1")
|
||||
|
@ -186,7 +192,8 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject().field("field1", "4").startArray("nested2").startObject().field("field2", "5").endObject().startObject().field("field2", "6").endObject().endArray().endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(7));
|
||||
assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6"));
|
||||
|
@ -229,7 +236,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true));
|
||||
assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startArray("nested1")
|
||||
|
@ -237,7 +244,8 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject().field("field1", "4").startArray("nested2").startObject().field("field2", "5").endObject().startObject().field("field2", "6").endObject().endArray().endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(7));
|
||||
assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6"));
|
||||
|
@ -280,7 +288,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false));
|
||||
assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(true));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startArray("nested1")
|
||||
|
@ -288,7 +296,8 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject().field("field1", "4").startArray("nested2").startObject().field("field2", "5").endObject().startObject().field("field2", "6").endObject().endArray().endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(7));
|
||||
assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6"));
|
||||
|
@ -326,7 +335,7 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
assertThat(nested1Mapper.nested().isNested(), equalTo(true));
|
||||
assertThat(nested1Mapper.dynamic(), equalTo(Dynamic.STRICT));
|
||||
|
||||
ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.startArray("nested1")
|
||||
|
@ -334,7 +343,8 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject().field("field1", "4").endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.docs().size(), equalTo(3));
|
||||
assertThat(doc.docs().get(0).get("nested1.field1"), equalTo("4"));
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
|
|||
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
@ -37,30 +38,33 @@ public class NullValueObjectMappingTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("obj1").endObject()
|
||||
.field("value1", "test1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("value1"), equalTo("test1"));
|
||||
|
||||
doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("obj1")
|
||||
.field("value1", "test1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("value1"), equalTo("test1"));
|
||||
|
||||
doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("obj1").field("field", "value").endObject()
|
||||
.field("value1", "test1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().get("obj1.field"), equalTo("value"));
|
||||
assertThat(doc.rootDoc().get("value1"), equalTo("test1"));
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.index.DocValuesType;
|
|||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
@ -47,11 +48,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 123)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -74,11 +76,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 123)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -96,11 +99,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 123)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -119,11 +123,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 123)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(3, fields.length);
|
||||
|
@ -147,11 +152,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "123")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -169,11 +175,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping, mapper2.mappingSource().toString());
|
||||
|
||||
ThrowingRunnable runnable = () -> mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "123")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
||||
assertThat(e.getCause().getMessage(), containsString("passed as String"));
|
||||
}
|
||||
|
@ -193,11 +200,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ThrowingRunnable runnable = () -> mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "a")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
||||
assertThat(e.getCause().getMessage(), containsString("For input string: \"a\""));
|
||||
|
||||
|
@ -207,11 +215,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "a")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(0, fields.length);
|
||||
|
@ -248,11 +257,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
|
||||
|
||||
Object missing;
|
||||
|
@ -274,11 +284,12 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
IndexableField pointField = fields[0];
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
|
@ -48,7 +49,7 @@ public class ObjectMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
|
||||
defaultMapper.parse("test", "type", "1", new BytesArray(" {\n" +
|
||||
defaultMapper.parse(SourceToParse.source("test", "type", "1", new BytesArray(" {\n" +
|
||||
" \"object\": {\n" +
|
||||
" \"array\":[\n" +
|
||||
" {\n" +
|
||||
|
@ -60,7 +61,8 @@ public class ObjectMapperTests extends ESSingleNodeTestCase {
|
|||
" ]\n" +
|
||||
" },\n" +
|
||||
" \"value\":\"value\"\n" +
|
||||
" }"));
|
||||
" }"),
|
||||
XContentType.JSON));
|
||||
});
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("different type"));
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ public class PathMatchDynamicTemplateTests 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/pathmatch/test-data.json");
|
||||
ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json));
|
||||
ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json),
|
||||
XContentType.JSON));
|
||||
client().admin().indices().preparePutMapping("test").setType("person")
|
||||
.setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
|
||||
docMapper = index.mapperService().documentMapper("person");
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.common.compress.CompressedXContent;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
@ -95,13 +96,14 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping.string()));
|
||||
assertEquals(mapping.string(), mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.field(getFromField(), getFrom(type))
|
||||
.field(getToField(), getTo(type))
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -122,13 +124,14 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping.string()));
|
||||
assertEquals(mapping.string(), mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.field(getFromField(), getFrom(type))
|
||||
.field(getToField(), getTo(type))
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(0, fields.length);
|
||||
|
@ -145,13 +148,14 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping.string()));
|
||||
assertEquals(mapping.string(), mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.field(getFromField(), getFrom(type))
|
||||
.field(getToField(), getTo(type))
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -170,13 +174,14 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping.string()));
|
||||
assertEquals(mapping.string(), mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.field(getFromField(), getFrom(type))
|
||||
.field(getToField(), getTo(type))
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -199,13 +204,14 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping.string(), mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.field(getFromField(), getFrom(type))
|
||||
.field(getToField(), getTo(type))
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -219,13 +225,14 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
|
||||
assertEquals(mapping.string(), mapper2.mappingSource().toString());
|
||||
|
||||
ThrowingRunnable runnable = () -> mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.field(getFromField(), "5.2")
|
||||
.field(getToField(), "10")
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
||||
assertThat(e.getCause().getMessage(), anyOf(containsString("passed as String"), containsString("failed to parse date")));
|
||||
}
|
||||
|
@ -243,26 +250,28 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
assertEquals(mapping.string(), mapper.mappingSource().toString());
|
||||
|
||||
// test null value for min and max
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.nullField(getFromField())
|
||||
.nullField(getToField())
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
assertEquals(2, doc.rootDoc().getFields("field").length);
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
IndexableField storedField = fields[1];
|
||||
assertThat(storedField.stringValue(), containsString(type.equals("date_range") ? Long.MAX_VALUE+"" : getMax(type)+""));
|
||||
|
||||
// test null max value
|
||||
doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.field(getFromField(), getFrom(type))
|
||||
.nullField(getToField())
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -293,11 +302,12 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
|||
assertEquals(mapping.string(), mapper.mappingSource().toString());
|
||||
|
||||
// test no bounds specified
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("field")
|
||||
.endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
|
|
@ -41,7 +41,8 @@ public class RoutingFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.startObject()
|
||||
.field("field", "value")
|
||||
.endObject()
|
||||
.bytes(), XContentType.JSON).routing("routing_value"));
|
||||
.bytes(),
|
||||
XContentType.JSON).routing("routing_value"));
|
||||
|
||||
assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value"));
|
||||
assertThat(doc.rootDoc().get("field"), equalTo("value"));
|
||||
|
@ -52,8 +53,8 @@ public class RoutingFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
try {
|
||||
docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject().field("_routing", "foo").endObject().bytes());
|
||||
docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject().field("_routing", "foo").endObject().bytes(),XContentType.JSON));
|
||||
fail("Expected failure to parse metadata field");
|
||||
} catch (MapperParsingException e) {
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Field [_routing] is a metadata field and cannot be added inside a document"));
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.index.DocValuesType;
|
|||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
@ -60,11 +61,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 123)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -109,11 +111,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 123)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -132,11 +135,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 123)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -155,11 +159,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", 123)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(3, fields.length);
|
||||
|
@ -183,11 +188,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "123")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -206,11 +212,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper2.mappingSource().toString());
|
||||
|
||||
ThrowingRunnable runnable = () -> mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ThrowingRunnable runnable = () -> mapper2.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "123")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
||||
assertThat(e.getCause().getMessage(), containsString("passed as String"));
|
||||
}
|
||||
|
@ -225,11 +232,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ThrowingRunnable runnable = () -> mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ThrowingRunnable runnable = () -> mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "a")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
|
||||
assertThat(e.getCause().getMessage(), containsString("For input string: \"a\""));
|
||||
|
||||
|
@ -240,11 +248,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = mapper2.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper2.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "a")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(0, fields.length);
|
||||
|
@ -264,11 +273,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
|
||||
|
||||
mapping = XContentFactory.jsonBuilder().startObject()
|
||||
|
@ -285,11 +295,12 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
|||
mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField("field")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
IndexableField pointField = fields[0];
|
||||
|
|
|
@ -51,16 +51,18 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
|
||||
DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
.field("field", "value")
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(XContentFactory.xContentType(doc.source()), equalTo(XContentType.JSON));
|
||||
|
||||
documentMapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
doc = documentMapper.parse("test", "type", "1", XContentFactory.smileBuilder().startObject()
|
||||
doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.smileBuilder().startObject()
|
||||
.field("field", "value")
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(XContentFactory.xContentType(doc.source()), equalTo(XContentType.SMILE));
|
||||
}
|
||||
|
@ -72,10 +74,11 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
.startObject("path1").field("field1", "value1").endObject()
|
||||
.startObject("path2").field("field2", "value2").endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField sourceField = doc.rootDoc().getField("_source");
|
||||
Map<String, Object> sourceAsMap;
|
||||
|
@ -93,10 +96,11 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
.startObject("path1").field("field1", "value1").endObject()
|
||||
.startObject("path2").field("field2", "value2").endObject()
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField sourceField = doc.rootDoc().getField("_source");
|
||||
Map<String, Object> sourceAsMap;
|
||||
|
@ -276,7 +280,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
try {
|
||||
documentMapper.parse("test", "type", "1", new BytesArray("{}}")); // extra end object (invalid JSON)
|
||||
documentMapper.parse(SourceToParse.source("test", "type", "1", new BytesArray("{}}"), XContentType.JSON)); // extra end object (invalid JSON)
|
||||
fail("Expected parse exception");
|
||||
} catch (MapperParsingException e) {
|
||||
assertNotNull(e.getRootCause());
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.store.RAMDirectory;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.fieldvisitor.CustomFieldsVisitor;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
|
@ -63,7 +64,7 @@ public class StoredNumericValuesTests extends ESSingleNodeTestCase {
|
|||
MapperService mapperService = createIndex("test").mapperService();
|
||||
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false);
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", 1)
|
||||
.field("field2", 1)
|
||||
|
@ -76,7 +77,8 @@ public class StoredNumericValuesTests extends ESSingleNodeTestCase {
|
|||
.field("field9", "2016-04-05")
|
||||
.field("field10", true)
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
writer.addDocument(doc.rootDoc());
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.elasticsearch.common.compress.CompressedXContent;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.engine.Engine;
|
||||
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
||||
|
@ -77,11 +78,12 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -108,11 +110,12 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -128,11 +131,12 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(0, fields.length);
|
||||
|
@ -150,11 +154,12 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(1, fields.length);
|
||||
|
@ -180,7 +185,8 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
for (String option : supportedOptions.keySet()) {
|
||||
jsonDoc.field(option, "1234");
|
||||
}
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", jsonDoc.endObject().bytes());
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", jsonDoc.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
for (Map.Entry<String, IndexOptions> entry : supportedOptions.entrySet()) {
|
||||
String field = entry.getKey();
|
||||
|
@ -201,11 +207,12 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.array("field", new String[] {"a", "b"})
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -240,11 +247,12 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
assertEquals(mapping, mapper.mappingSource().toString());
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.array("field", new String[] {"a", "b"})
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
IndexableField[] fields = doc.rootDoc().getFields("field");
|
||||
assertEquals(2, fields.length);
|
||||
|
@ -396,7 +404,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", "1234")
|
||||
.field("field2", "1234")
|
||||
|
@ -405,7 +413,8 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|||
.field("field5", "1234")
|
||||
.field("field6", "1234")
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getField("field1").fieldType().storeTermVectors(), equalTo(false));
|
||||
assertThat(doc.rootDoc().getField("field1").fieldType().storeTermVectorOffsets(), equalTo(false));
|
||||
|
|
|
@ -26,12 +26,14 @@ import org.apache.lucene.search.suggest.document.ContextSuggestField;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.mapper.ParseContext;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
import org.elasticsearch.index.mapper.SourceToParse;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.search.suggest.completion.context.CategoryContextMapping;
|
||||
import org.elasticsearch.search.suggest.completion.context.ContextBuilder;
|
||||
|
@ -62,7 +64,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("completion")
|
||||
.startObject()
|
||||
|
@ -79,7 +81,8 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertContextSuggestFields(fields, 7);
|
||||
}
|
||||
|
@ -100,7 +103,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("completion")
|
||||
.startObject()
|
||||
|
@ -112,7 +115,8 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertContextSuggestFields(fields, 3);
|
||||
}
|
||||
|
@ -133,7 +137,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("completion")
|
||||
.array("input", "suggestion5", "suggestion6", "suggestion7")
|
||||
|
@ -143,7 +147,8 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
.field("weight", 5)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertContextSuggestFields(fields, 3);
|
||||
}
|
||||
|
@ -181,7 +186,8 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endArray()
|
||||
.endObject();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", builder.bytes());
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", builder.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertContextSuggestFields(fields, 3);
|
||||
}
|
||||
|
|
|
@ -23,11 +23,13 @@ import org.apache.lucene.index.IndexableField;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
import org.elasticsearch.index.mapper.SourceToParse;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.search.suggest.completion.context.ContextBuilder;
|
||||
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
|
||||
|
@ -62,7 +64,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("completion")
|
||||
.startObject()
|
||||
|
@ -79,7 +81,8 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertContextSuggestFields(fields, 7);
|
||||
}
|
||||
|
@ -101,7 +104,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("completion")
|
||||
.startObject()
|
||||
|
@ -116,7 +119,8 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertContextSuggestFields(fields, 3);
|
||||
}
|
||||
|
@ -137,7 +141,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
||||
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
|
||||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder()
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("completion")
|
||||
.array("input", "suggestion5", "suggestion6", "suggestion7")
|
||||
|
@ -156,7 +160,8 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
.field("weight", 5)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertContextSuggestFields(fields, 3);
|
||||
}
|
||||
|
@ -194,7 +199,8 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endArray()
|
||||
.endObject();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", builder.bytes());
|
||||
ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", builder.bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
assertContextSuggestFields(fields, 3);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
|
@ -52,6 +53,7 @@ import org.elasticsearch.index.mapper.MapperParsingException;
|
|||
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.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.BoostingQueryBuilder;
|
||||
import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
|
||||
|
@ -244,9 +246,12 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
public void testPercolatorFieldMapper() throws Exception {
|
||||
addQueryMapping();
|
||||
QueryBuilder queryBuilder = termQuery("field", "value");
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject()
|
||||
.field(fieldName, queryBuilder)
|
||||
.endObject().bytes());
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", XContentFactory
|
||||
.jsonBuilder()
|
||||
.startObject()
|
||||
.field(fieldName, queryBuilder)
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
assertThat(doc.rootDoc().getFields(fieldType.queryTermsField.name()).length, equalTo(1));
|
||||
assertThat(doc.rootDoc().getFields(fieldType.queryTermsField.name())[0].binaryValue().utf8ToString(), equalTo("field\0value"));
|
||||
|
@ -259,9 +264,12 @@ 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(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject()
|
||||
doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", XContentFactory
|
||||
.jsonBuilder()
|
||||
.startObject()
|
||||
.field(fieldName, queryBuilder)
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
assertThat(doc.rootDoc().getFields(fieldType.extractionResultField.name()).length, equalTo(1));
|
||||
assertThat(doc.rootDoc().getFields(fieldType.extractionResultField.name())[0].stringValue(),
|
||||
equalTo(EXTRACTION_FAILED));
|
||||
|
@ -282,10 +290,11 @@ 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(typeName).parse("test", typeName, "1",
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
XContentFactory.jsonBuilder().startObject()
|
||||
.field(fieldName, query)
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
BytesRef qbSource = doc.rootDoc().getFields(fieldType.queryBuilderField.name())[0].binaryValue();
|
||||
assertQueryBuilder(qbSource, query);
|
||||
}
|
||||
|
@ -295,9 +304,12 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
addQueryMapping();
|
||||
client().prepareIndex("remote", "type", "1").setSource("field", "value").get();
|
||||
QueryBuilder queryBuilder = termsLookupQuery("field", new TermsLookup("remote", "type", "1", "field"));
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject()
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", XContentFactory
|
||||
.jsonBuilder()
|
||||
.startObject()
|
||||
.field(fieldName, queryBuilder)
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
BytesRef qbSource = doc.rootDoc().getFields(fieldType.queryBuilderField.name())[0].binaryValue();
|
||||
assertQueryBuilder(qbSource, queryBuilder.rewrite(indexService.newQueryShardContext(
|
||||
randomInt(20), null, () -> { throw new UnsupportedOperationException(); })));
|
||||
|
@ -307,9 +319,12 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
public void testPercolatorFieldMapperUnMappedField() throws Exception {
|
||||
addQueryMapping();
|
||||
MapperParsingException exception = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject()
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", XContentFactory
|
||||
.jsonBuilder()
|
||||
.startObject()
|
||||
.field(fieldName, termQuery("unmapped_field", "value"))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
});
|
||||
assertThat(exception.getCause(), instanceOf(QueryShardException.class));
|
||||
assertThat(exception.getCause().getMessage(), equalTo("No field mapping can be found for the field with name [unmapped_field]"));
|
||||
|
@ -318,14 +333,21 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
public void testPercolatorFieldMapper_noQuery() throws Exception {
|
||||
addQueryMapping();
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject()
|
||||
.endObject().bytes());
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", XContentFactory
|
||||
.jsonBuilder()
|
||||
.startObject()
|
||||
.endObject()
|
||||
.bytes(),
|
||||
XContentType.JSON));
|
||||
assertThat(doc.rootDoc().getFields(fieldType.queryBuilderField.name()).length, equalTo(0));
|
||||
|
||||
try {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject()
|
||||
.nullField(fieldName)
|
||||
.endObject().bytes());
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", XContentFactory
|
||||
.jsonBuilder()
|
||||
.startObject()
|
||||
.nullField(fieldName)
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
} catch (MapperParsingException e) {
|
||||
assertThat(e.getDetailedMessage(), containsString("query malformed, must start with start_object"));
|
||||
}
|
||||
|
@ -357,12 +379,12 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true);
|
||||
|
||||
QueryBuilder queryBuilder = matchQuery("field", "value");
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field("query_field1", queryBuilder)
|
||||
.field("query_field2", queryBuilder)
|
||||
.endObject().bytes()
|
||||
);
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
assertThat(doc.rootDoc().getFields().size(), equalTo(14)); // also includes all other meta fields
|
||||
BytesRef queryBuilderAsBytes = doc.rootDoc().getField("query_field1.query_builder_field").binaryValue();
|
||||
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
|
||||
|
@ -388,35 +410,35 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true);
|
||||
|
||||
QueryBuilder queryBuilder = matchQuery("field", "value");
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject().startObject("object_field")
|
||||
.field("query_field", queryBuilder)
|
||||
.endObject().endObject().bytes()
|
||||
);
|
||||
.endObject().endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
assertThat(doc.rootDoc().getFields().size(), equalTo(11)); // also includes all other meta fields
|
||||
BytesRef queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
|
||||
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
|
||||
|
||||
doc = mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.startArray("object_field")
|
||||
.startObject().field("query_field", queryBuilder).endObject()
|
||||
.endArray()
|
||||
.endObject().bytes()
|
||||
);
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
assertThat(doc.rootDoc().getFields().size(), equalTo(11)); // also includes all other meta fields
|
||||
queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
|
||||
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
|
||||
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.startArray("object_field")
|
||||
.startObject().field("query_field", queryBuilder).endObject()
|
||||
.startObject().field("query_field", queryBuilder).endObject()
|
||||
.endArray()
|
||||
.endObject().bytes()
|
||||
);
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
}
|
||||
);
|
||||
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||
|
@ -426,42 +448,47 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
public void testRangeQueryWithNowRangeIsForbidden() throws Exception {
|
||||
addQueryMapping();
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").from("2016-01-01||/D").to("now"))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
}
|
||||
);
|
||||
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||
e = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").from("2016-01-01||/D").to("now/D"))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
}
|
||||
);
|
||||
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||
e = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").from("now-1d").to("now"))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
}
|
||||
);
|
||||
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||
e = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").from("now"))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
}
|
||||
);
|
||||
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||
e = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").to("now"))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
}
|
||||
);
|
||||
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||
|
@ -471,31 +498,39 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
public void testVerifyRangeQueryWithNullBounds() throws Exception {
|
||||
addQueryMapping();
|
||||
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").from("now").to(null))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
}
|
||||
);
|
||||
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||
e = expectThrows(MapperParsingException.class, () -> {
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").from(null).to("now"))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
}
|
||||
);
|
||||
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||
|
||||
// No validation failures:
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").from("2016-01-01").to(null))
|
||||
.endObject().bytes());
|
||||
mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
jsonBuilder().startObject()
|
||||
.field(fieldName, rangeQuery("date_field").from(null).to("2016-01-01"))
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
|
||||
}
|
||||
|
||||
public void testUnsupportedQueries() {
|
||||
|
@ -570,10 +605,11 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
query.endObject();
|
||||
query.endObject();
|
||||
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
XContentFactory.jsonBuilder().startObject()
|
||||
.rawField(fieldName, new BytesArray(query.string()), query.contentType())
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
BytesRef querySource = doc.rootDoc().getFields(fieldType.queryBuilderField.name())[0].binaryValue();
|
||||
Map<String, Object> parsedQuery = XContentHelper.convertToMap(new BytesArray(querySource), true).v2();
|
||||
assertEquals(Script.DEFAULT_SCRIPT_LANG, XContentMapValues.extractValue("script.script.lang", parsedQuery));
|
||||
|
@ -597,10 +633,11 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
|
|||
query.endObject();
|
||||
query.endObject();
|
||||
|
||||
doc = mapperService.documentMapper(typeName).parse("test", typeName, "1",
|
||||
doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1",
|
||||
XContentFactory.jsonBuilder().startObject()
|
||||
.rawField(fieldName, new BytesArray(query.string()), query.contentType())
|
||||
.endObject().bytes());
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
querySource = doc.rootDoc().getFields(fieldType.queryBuilderField.name())[0].binaryValue();
|
||||
parsedQuery = XContentHelper.convertToMap(new BytesArray(querySource), true).v2();
|
||||
assertEquals(Script.DEFAULT_SCRIPT_LANG,
|
||||
|
|
|
@ -27,11 +27,13 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
import org.elasticsearch.index.mapper.SourceToParse;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.indices.mapper.MapperRegistry;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
@ -78,7 +80,11 @@ public class Murmur3FieldMapperTests extends ESSingleNodeTestCase {
|
|||
.field("type", "murmur3")
|
||||
.endObject().endObject().endObject().endObject().string();
|
||||
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||
ParsedDocument parsedDoc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").endObject().bytes());
|
||||
ParsedDocument parsedDoc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field", "value")
|
||||
.endObject().bytes(),
|
||||
XContentType.JSON));
|
||||
IndexableField[] fields = parsedDoc.rootDoc().getFields("field");
|
||||
assertNotNull(fields);
|
||||
assertEquals(Arrays.toString(fields), 1, fields.length);
|
||||
|
|
Loading…
Reference in New Issue