diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MultifieldAttachmentMapperTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MultifieldAttachmentMapperTests.java index 6b781a6f4a6..5459bc6aef8 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MultifieldAttachmentMapperTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MultifieldAttachmentMapperTests.java @@ -153,4 +153,45 @@ public class MultifieldAttachmentMapperTests extends AttachmentUnitTestCase { // In mapping we set store:true for suggest subfield assertThat(doc.rootDoc().getField("file.name.suggest").fieldType().stored(), is(true)); } + + public void testAllExternalValues() throws Exception { + String originalText = "This is an elasticsearch mapper attachment test."; + String forcedName = randomAsciiOfLength(20); + String forcedLanguage = randomAsciiOfLength(20); + String forcedContentType = randomAsciiOfLength(20); + + String bytes = Base64.encodeBytes(originalText.getBytes(StandardCharsets.ISO_8859_1)); + threadPool = new ThreadPool("testing-only"); + + MapperService mapperService = MapperTestUtils.newMapperService(createTempDir(), + Settings.builder().put(AttachmentMapper.INDEX_ATTACHMENT_DETECT_LANGUAGE_SETTING.getKey(), true).build(), + getIndicesModuleWithRegisteredAttachmentMapper()); + + String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/multifield/multifield-mapping.json"); + + DocumentMapper documentMapper = mapperService.documentMapperParser().parse("person", new CompressedXContent(mapping)); + + ParsedDocument doc = documentMapper.parse("person", "person", "1", XContentFactory.jsonBuilder() + .startObject() + .startObject("file") + .field("_content", bytes) + .field("_name", forcedName) + .field("_language", forcedLanguage) + .field("_content_type", forcedContentType) + .endObject() + .endObject() + .bytes()); + + // Note that we don't support forcing values for _title and _keywords + + assertThat(doc.rootDoc().getField("file.content"), notNullValue()); + assertThat(doc.rootDoc().getField("file.content").stringValue(), is(originalText + "\n")); + + assertThat(doc.rootDoc().getField("file.name"), notNullValue()); + assertThat(doc.rootDoc().getField("file.name").stringValue(), is(forcedName)); + assertThat(doc.rootDoc().getField("file.language"), notNullValue()); + assertThat(doc.rootDoc().getField("file.language").stringValue(), is(forcedLanguage)); + assertThat(doc.rootDoc().getField("file.content_type"), notNullValue()); + assertThat(doc.rootDoc().getField("file.content_type").stringValue(), is(forcedContentType)); + } }