@Test public void testMultipleDocsEncryptedLast() throws IOException { DocumentMapperParser mapperParser = new DocumentMapperParser( new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null); mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json"); DocumentMapper docMapper = mapperParser.parse(mapping); byte[] html = copyToBytesFromClasspath( "/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html"); byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf"); BytesReference json = jsonBuilder() .startObject() .field("_id", 1) .field("file1", html) .field("file2", pdf) .endObject() .bytes(); ParseContext.Document doc = docMapper.parse(json).rootDoc(); assertThat( doc.get(docMapper.mappers().smartName("file1").mapper().names().indexName()), containsString("World")); assertThat( doc.get(docMapper.mappers().smartName("file1.title").mapper().names().indexName()), equalTo("Hello")); assertThat( doc.get(docMapper.mappers().smartName("file1.author").mapper().names().indexName()), equalTo("kimchy")); assertThat( doc.get(docMapper.mappers().smartName("file1.keywords").mapper().names().indexName()), equalTo("elasticsearch,cool,bonsai")); assertThat( doc.get(docMapper.mappers().smartName("file1.content_type").mapper().names().indexName()), equalTo("text/html; charset=ISO-8859-1")); assertThat( doc.getField( docMapper.mappers().smartName("file1.content_length").mapper().names().indexName()) .numericValue() .longValue(), is(344L)); assertThat( doc.get(docMapper.mappers().smartName("file2").mapper().names().indexName()), nullValue()); assertThat( doc.get(docMapper.mappers().smartName("file2.title").mapper().names().indexName()), nullValue()); assertThat( doc.get(docMapper.mappers().smartName("file2.author").mapper().names().indexName()), nullValue()); assertThat( doc.get(docMapper.mappers().smartName("file2.keywords").mapper().names().indexName()), nullValue()); assertThat( doc.get(docMapper.mappers().smartName("file2.content_type").mapper().names().indexName()), nullValue()); assertThat( doc.getField( docMapper.mappers().smartName("file2.content_length").mapper().names().indexName()), nullValue()); }
@Before public void setupMapperParser() { mapperParser = MapperTestUtils.newMapperParser(); mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); }