use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class SizeMappingTests method testSizeDisabled.
public void testSizeDisabled() throws Exception {
IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=false");
DocumentMapper docMapper = service.mapperService().documentMapper("type");
BytesReference source = XContentFactory.jsonBuilder().startObject().field("field", "value").endObject().bytes();
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON));
assertThat(doc.rootDoc().getField("_size"), nullValue());
}
use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class MultiFieldTests method testBuildThenParse.
public void testBuildThenParse() throws Exception {
IndexService indexService = createIndex("test");
DocumentMapper builderDocMapper = new DocumentMapper.Builder(new RootObjectMapper.Builder("person").add(new TextFieldMapper.Builder("name").store(true).addMultiField(new TextFieldMapper.Builder("indexed").index(true).tokenized(true)).addMultiField(new TextFieldMapper.Builder("not_indexed").index(false).store(true))), indexService.mapperService()).build(indexService.mapperService());
String builtMapping = builderDocMapper.mappingSource().string();
// System.out.println(builtMapping);
// reparse it
DocumentMapper docMapper = indexService.mapperService().documentMapperParser().parse("person", new CompressedXContent(builtMapping));
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
Document doc = docMapper.parse("test", "person", "1", json).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));
assertThat(f.stringValue(), equalTo("some name"));
assertThat(f.fieldType().stored(), equalTo(true));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
f = doc.getField("name.indexed");
assertThat(f.name(), equalTo("name.indexed"));
assertThat(f.stringValue(), equalTo("some name"));
assertThat(f.fieldType().tokenized(), equalTo(true));
assertThat(f.fieldType().stored(), equalTo(false));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
f = doc.getField("name.not_indexed");
assertThat(f.name(), equalTo("name.not_indexed"));
assertThat(f.stringValue(), equalTo("some name"));
assertThat(f.fieldType().stored(), equalTo(true));
assertEquals(IndexOptions.NONE, f.fieldType().indexOptions());
}
use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class NullValueObjectMappingTests method testNullValueObject.
public void testNullValueObject() throws IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("obj1").field("type", "object").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().startObject().startObject("obj1").endObject().field("value1", "test1").endObject().bytes());
assertThat(doc.rootDoc().get("value1"), equalTo("test1"));
doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().nullField("obj1").field("value1", "test1").endObject().bytes());
assertThat(doc.rootDoc().get("value1"), equalTo("test1"));
doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().startObject("obj1").field("field", "value").endObject().field("value1", "test1").endObject().bytes());
assertThat(doc.rootDoc().get("obj1.field"), equalTo("value"));
assertThat(doc.rootDoc().get("value1"), equalTo("test1"));
}
use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class RoutingFieldMapperTests method testRoutingMapper.
public void testRoutingMapper() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").endObject().bytes(), XContentType.JSON).routing("routing_value"));
assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value"));
assertThat(doc.rootDoc().get("field"), equalTo("value"));
}
use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class RoutingFieldMapperTests method testIncludeInObjectNotAllowed.
public void testIncludeInObjectNotAllowed() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
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());
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"));
}
}
Aggregations