public void testSimpleParserNoTypeNoId() throws Exception { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json"); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping); BytesReference json = new BytesArray( copyToBytesFromClasspath( "/org/elasticsearch/index/mapper/simple/test1-notype-noid.json")); Document doc = docMapper.parse("test", "person", "1", json).rootDoc(); assertThat( doc.get(docMapper.uidMapper().fieldType().names().indexName()), equalTo(Uid.createUid("person", "1"))); assertThat( doc.get(docMapper.mappers().getMapper("name.first").fieldType().names().indexName()), equalTo("shay")); }
public void testSimpleMapper() throws Exception { IndexService indexService = createIndex("test"); Settings settings = indexService.getIndexSettings().getSettings(); DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser(); DocumentMapper docMapper = doc( settings, rootObject("person") .add(object("name").add(stringField("first").store(true).index(false))), indexService.mapperService()) .build(indexService.mapperService(), mapperParser); BytesReference json = new BytesArray( copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json")); Document doc = docMapper.parse("test", "person", "1", json).rootDoc(); assertThat( doc.get(docMapper.mappers().getMapper("name.first").fieldType().names().indexName()), equalTo("shay")); doc = docMapper.parse("test", "person", "1", json).rootDoc(); }