use of org.elasticsearch.index.mapper.FieldMapper in project elasticsearch by elastic.
the class CategoryContextMappingTests method testIndexingWithContextList.
public void testIndexingWithContextList() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().endArray().endObject().endObject().endObject().endObject().string();
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().startObject().startObject("completion").array("input", "suggestion5", "suggestion6", "suggestion7").startObject("contexts").array("ctx", "ctx1", "ctx2", "ctx3").endObject().field("weight", 5).endObject().endObject().bytes());
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertContextSuggestFields(fields, 3);
}
use of org.elasticsearch.index.mapper.FieldMapper in project elasticsearch by elastic.
the class DynamicTemplatesTests method testSimpleWithXContentTraverse.
public void testSimpleWithXContentTraverse() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-mapping.json");
IndexService index = createIndex("test");
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));
client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
docMapper = index.mapperService().documentMapper("person");
Document doc = parsedDoc.rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));
assertThat(f.binaryValue(), equalTo(new BytesRef("some name")));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
assertThat(f.fieldType().tokenized(), equalTo(false));
FieldMapper fieldMapper = docMapper.mappers().getMapper("name");
assertNotNull(fieldMapper);
f = doc.getField("multi1");
assertThat(f.name(), equalTo("multi1"));
assertThat(f.stringValue(), equalTo("multi 1"));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
assertThat(f.fieldType().tokenized(), equalTo(true));
fieldMapper = docMapper.mappers().getMapper("multi1");
assertNotNull(fieldMapper);
f = doc.getField("multi1.org");
assertThat(f.name(), equalTo("multi1.org"));
assertThat(f.binaryValue(), equalTo(new BytesRef("multi 1")));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
assertThat(f.fieldType().tokenized(), equalTo(false));
fieldMapper = docMapper.mappers().getMapper("multi1.org");
assertNotNull(fieldMapper);
f = doc.getField("multi2");
assertThat(f.name(), equalTo("multi2"));
assertThat(f.stringValue(), equalTo("multi 2"));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
assertThat(f.fieldType().tokenized(), equalTo(true));
fieldMapper = docMapper.mappers().getMapper("multi2");
assertNotNull(fieldMapper);
f = doc.getField("multi2.org");
assertThat(f.name(), equalTo("multi2.org"));
assertThat(f.binaryValue(), equalTo(new BytesRef("multi 2")));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
assertThat(f.fieldType().tokenized(), equalTo(false));
fieldMapper = docMapper.mappers().getMapper("multi2.org");
assertNotNull(fieldMapper);
}
use of org.elasticsearch.index.mapper.FieldMapper in project elasticsearch by elastic.
the class PathMatchDynamicTemplateTests method testSimple.
public void testSimple() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-mapping.json");
IndexService index = createIndex("test");
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));
client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
docMapper = index.mapperService().documentMapper("person");
Document doc = parsedDoc.rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));
assertThat(f.stringValue(), equalTo("top_level"));
assertThat(f.fieldType().stored(), equalTo(false));
FieldMapper fieldMapper = docMapper.mappers().getMapper("name");
assertThat(fieldMapper.fieldType().stored(), equalTo(false));
f = doc.getField("obj1.name");
assertThat(f.name(), equalTo("obj1.name"));
assertThat(f.fieldType().stored(), equalTo(true));
fieldMapper = docMapper.mappers().getMapper("obj1.name");
assertThat(fieldMapper.fieldType().stored(), equalTo(true));
f = doc.getField("obj1.obj2.name");
assertThat(f.name(), equalTo("obj1.obj2.name"));
assertThat(f.fieldType().stored(), equalTo(false));
fieldMapper = docMapper.mappers().getMapper("obj1.obj2.name");
assertThat(fieldMapper.fieldType().stored(), equalTo(false));
// verify more complex path_match expressions
fieldMapper = docMapper.mappers().getMapper("obj3.obj4.prop1");
assertNotNull(fieldMapper);
}
Aggregations