Add a test for forced values in mapper-attachments plugin
This PR just adds a new test where we check that we forcing a value in the JSON document actually works as expected: ```json { "file": { "_content": "BASE64" "_name": "12-240.pdf", "_language": "en", "_content_type": "pdf" } } ``` Note that we don't support forcing all values. So sending: ```json { "file": { "_content": "BASE64" "_name": "12-240.pdf", "_title": "12-240.pdf", "_keywords": "Div42 Src580 LGE Mechtech", "_language": "en", "_content_type": "pdf" } } ``` Will have absolutely no effect on fields `title` and `keywords`. Note that when `_language` is set, it only works if `index.mapping.attachment.detect_language` is set to `true`. Related to https://discuss.elastic.co/t/mapper-attachments/46615/4
This commit is contained in:
parent
e0cde29a68
commit
c6b1beb083
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue