From 80c7cf54f8749f1b38fd68b6c3ca8f1af306e39e Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Thu, 3 Dec 2015 09:30:18 +0100 Subject: [PATCH] throw exception if a copy_to is within a multi field Copy to within multi field is ignored from 2.0 on, see #10802. Instead of just ignoring it, we should throw an exception if this is found in the mapping when a mapping is added. For already existing indices we should at least log a warning. related to #14946 --- .../elasticsearch/index/mapper/Mapper.java | 19 ++++- .../index/mapper/core}/MapperTestUtils.java | 52 ++++++++----- .../index/mapper/core/TypeParsers.java | 26 +++++-- .../core/MultiFieldCopyToMapperTests.java | 74 +++++++++++++++++++ .../migration/migrate_2_0/mapping.asciidoc | 8 ++ .../DateAttachmentMapperTests.java | 3 +- .../attachments/EncryptedDocMapperTests.java | 8 +- ...anguageDetectionAttachmentMapperTests.java | 4 +- .../attachments/MetadataMapperTests.java | 4 +- .../MultifieldAttachmentMapperTests.java | 6 +- .../SimpleAttachmentMapperTests.java | 9 ++- .../mapper/attachments/StandaloneRunner.java | 4 +- .../mapper/attachments/VariousDocTests.java | 8 +- 13 files changed, 176 insertions(+), 49 deletions(-) rename {plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments => core/src/main/java/org/elasticsearch/index/mapper/core}/MapperTestUtils.java (58%) create mode 100644 core/src/test/java/org/elasticsearch/index/mapper/core/MultiFieldCopyToMapperTests.java diff --git a/core/src/main/java/org/elasticsearch/index/mapper/Mapper.java b/core/src/main/java/org/elasticsearch/index/mapper/Mapper.java index 9d5c78ce31c13..ae8d97e189754 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/Mapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/Mapper.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.mapper; -import com.google.common.collect.ImmutableMap; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; @@ -134,6 +133,24 @@ public Version indexVersionCreated() { public ParseFieldMatcher parseFieldMatcher() { return parseFieldMatcher; } + + public boolean isWithinMultiField() { return false; } + + protected Map typeParsers() { return typeParsers; } + + public ParserContext createMultiFieldContext(ParserContext in) { + return new MultiFieldParserContext(in) { + @Override + public boolean isWithinMultiField() { return true; } + }; + } + + class MultiFieldParserContext extends ParserContext { + MultiFieldParserContext(ParserContext in) { + super(in.type(), in.analysisService, in.similarityLookupService(), in.mapperService(), in.typeParsers(), in.indexVersionCreated(), in.parseFieldMatcher()); + } + } + } Mapper.Builder parse(String name, Map node, ParserContext parserContext) throws MapperParsingException; diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperTestUtils.java b/core/src/main/java/org/elasticsearch/index/mapper/core/MapperTestUtils.java similarity index 58% rename from plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperTestUtils.java rename to core/src/main/java/org/elasticsearch/index/mapper/core/MapperTestUtils.java index b1d75756a8aaa..e6e85c600151b 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperTestUtils.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/MapperTestUtils.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.mapper.attachments; +package org.elasticsearch.index.mapper.core; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -31,6 +31,7 @@ import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.AnalysisService; +import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.similarity.SimilarityLookupService; @@ -44,37 +45,50 @@ public class MapperTestUtils { public static MapperService newMapperService(Path tempDir, Settings indexSettings) { - return newMapperService(new Index("test"), Settings.builder() - .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) - .put("path.home", tempDir) - .put(indexSettings) - .build()); + return newMapperService(tempDir, indexSettings, Version.CURRENT); + + } + + public static MapperService newMapperService(Path tempDir, Settings indexSettings, Version version) { + return newMapperService(tempDir, indexSettings, null, null, version); + + } + + public static MapperService newMapperService(Path tempDir, Settings indexSettings, String contentType, Mapper.TypeParser typeParser) { + return newMapperService(tempDir, indexSettings, contentType, typeParser, Version.CURRENT); } - private static MapperService newMapperService(Index index, Settings indexSettings) { + private static MapperService newMapperService(Path tempDir, Settings indexSettings, String contentType, Mapper.TypeParser typeParser, Version version) { IndicesModule indicesModule = new IndicesModule(); - indicesModule.registerMapper(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); + if (contentType != null && typeParser != null) { + indicesModule.registerMapper(contentType, typeParser); + } + Settings settings = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, version) + .put("path.home", tempDir) + .put(indexSettings) + .build(); MapperRegistry mapperRegistry = indicesModule.getMapperRegistry(); - return new MapperService(index, - indexSettings, - newAnalysisService(indexSettings), - newSimilarityLookupService(indexSettings), - null, - mapperRegistry); + return new MapperService(new Index("test"), + settings, + newAnalysisService(settings), + newSimilarityLookupService(settings), + null, + mapperRegistry); } - private static AnalysisService newAnalysisService(Settings indexSettings) { + private static AnalysisService newAnalysisService(Settings indexSettings) { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector(); Index index = new Index("test"); Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, indexSettings), - new IndexNameModule(index), - new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector); + new IndexSettingsModule(index, indexSettings), + new IndexNameModule(index), + new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector); return injector.getInstance(AnalysisService.class); } - private static SimilarityLookupService newSimilarityLookupService(Settings indexSettings) { + private static SimilarityLookupService newSimilarityLookupService(Settings indexSettings) { return new SimilarityLookupService(new Index("test"), indexSettings); } } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java b/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java index 0e1367177df1d..714459fa1e9aa 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.Joda; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.loader.SettingsLoader; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -184,11 +185,12 @@ public static void parseNumberField(NumberFieldMapper.Builder builder, String na public static void parseField(FieldMapper.Builder builder, String name, Map fieldNode, Mapper.TypeParser.ParserContext parserContext) { NamedAnalyzer indexAnalyzer = builder.fieldType().indexAnalyzer(); NamedAnalyzer searchAnalyzer = builder.fieldType().searchAnalyzer(); + Version indexVersionCreated = parserContext.indexVersionCreated(); for (Iterator> iterator = fieldNode.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = iterator.next(); final String propName = Strings.toUnderscoreCase(entry.getKey()); final Object propNode = entry.getValue(); - if (propName.equals("index_name") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) { + if (propName.equals("index_name") && indexVersionCreated.before(Version.V_2_0_0_beta1)) { builder.indexName(propNode.toString()); iterator.remove(); } else if (propName.equals("store")) { @@ -242,7 +244,7 @@ public static void parseField(FieldMapper.Builder builder, String name, Map> within a <> is ignored from version 2.0 on. With any version after +2.1 or 2.0.1 creating a mapping that has a copy_to within a multi field will result +in an exception. + + diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/DateAttachmentMapperTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/DateAttachmentMapperTests.java index 858ed8a767f0b..372e6a0018190 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/DateAttachmentMapperTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/DateAttachmentMapperTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.DocumentMapperParser; +import org.elasticsearch.index.mapper.core.MapperTestUtils; import org.elasticsearch.index.mapper.core.StringFieldMapper; import org.junit.Before; @@ -37,7 +38,7 @@ public class DateAttachmentMapperTests extends AttachmentUnitTestCase { @Before public void setupMapperParser() throws Exception { - mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY).documentMapperParser(); + mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); } public void testSimpleMappings() throws Exception { diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/EncryptedDocMapperTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/EncryptedDocMapperTests.java index e086d9ba5c4e2..b142ec9a01f7f 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/EncryptedDocMapperTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/EncryptedDocMapperTests.java @@ -25,7 +25,7 @@ import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.ParseContext; -import org.elasticsearch.mapper.attachments.AttachmentMapper; +import org.elasticsearch.index.mapper.core.MapperTestUtils; import java.io.IOException; @@ -42,7 +42,7 @@ public class EncryptedDocMapperTests extends AttachmentUnitTestCase { public void testMultipleDocsEncryptedLast() throws IOException { - DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY).documentMapperParser(); + DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json"); DocumentMapper docMapper = mapperParser.parse(mapping); @@ -72,7 +72,7 @@ public void testMultipleDocsEncryptedLast() throws IOException { } public void testMultipleDocsEncryptedFirst() throws IOException { - DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY).documentMapperParser(); + DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json"); DocumentMapper docMapper = mapperParser.parse(mapping); byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/htmlWithValidDateMeta.html"); @@ -105,7 +105,7 @@ public void testMultipleDocsEncryptedNotIgnoringErrors() throws IOException { DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.builder() .put("index.mapping.attachment.ignore_errors", false) - .build()).documentMapperParser(); + .build(), AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json"); DocumentMapper docMapper = mapperParser.parse(mapping); diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/LanguageDetectionAttachmentMapperTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/LanguageDetectionAttachmentMapperTests.java index b2d361fe847fa..019e5b9cfca92 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/LanguageDetectionAttachmentMapperTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/LanguageDetectionAttachmentMapperTests.java @@ -24,8 +24,8 @@ import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.ParseContext; +import org.elasticsearch.index.mapper.core.MapperTestUtils; import org.elasticsearch.index.mapper.core.StringFieldMapper; -import org.elasticsearch.mapper.attachments.AttachmentMapper; import org.junit.Before; import java.io.IOException; @@ -52,7 +52,7 @@ public void setupMapperParser(boolean langDetect) throws IOException { DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.settingsBuilder() .put("index.mapping.attachment.detect_language", langDetect) - .build()).documentMapperParser(); + .build(), AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/language/language-mapping.json"); docMapper = mapperParser.parse(mapping); diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MetadataMapperTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MetadataMapperTests.java index cf2a130829f34..c4aa7a084c146 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MetadataMapperTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MetadataMapperTests.java @@ -25,7 +25,7 @@ import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.ParseContext; -import org.elasticsearch.mapper.attachments.AttachmentMapper; +import org.elasticsearch.index.mapper.core.MapperTestUtils; import java.io.IOException; @@ -44,7 +44,7 @@ protected void checkMeta(String filename, Settings otherSettings, Long expectedD .put(this.testSettings) .put(otherSettings) .build(); - DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), settings).documentMapperParser(); + DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), settings, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/metadata/test-mapping.json"); DocumentMapper docMapper = mapperParser.parse(mapping); 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 4f070bd0dd1f7..59b88ed051c53 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 @@ -27,8 +27,8 @@ import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.core.DateFieldMapper; +import org.elasticsearch.index.mapper.core.MapperTestUtils; import org.elasticsearch.index.mapper.core.StringFieldMapper; -import org.elasticsearch.mapper.attachments.AttachmentMapper; import org.elasticsearch.threadpool.ThreadPool; import org.junit.After; import org.junit.Before; @@ -48,7 +48,7 @@ public class MultifieldAttachmentMapperTests extends AttachmentUnitTestCase { @Before public void setupMapperParser() throws Exception { - mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY).documentMapperParser(); + mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); } @@ -91,7 +91,7 @@ public void testExternalValues() throws Exception { String bytes = Base64.encodeBytes(originalText.getBytes(StandardCharsets.ISO_8859_1)); threadPool = new ThreadPool("testing-only"); - MapperService mapperService = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY); + MapperService mapperService = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/multifield/multifield-mapping.json"); diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/SimpleAttachmentMapperTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/SimpleAttachmentMapperTests.java index 0ceb4c0cdcd5d..ca6a8244dc3d1 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/SimpleAttachmentMapperTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/SimpleAttachmentMapperTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.ParseContext; +import org.elasticsearch.index.mapper.core.MapperTestUtils; import org.junit.Test; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; @@ -42,7 +43,7 @@ public class SimpleAttachmentMapperTests extends AttachmentUnitTestCase { public void testSimpleMappings() throws Exception { - DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY).documentMapperParser(); + DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/simple/test-mapping.json"); DocumentMapper docMapper = mapperParser.parse(mapping); byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testXHTML.html"); @@ -71,7 +72,7 @@ public void testContentBackcompat() throws Exception { DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id) - .build()).documentMapperParser(); + .build(), AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/simple/test-mapping.json"); DocumentMapper docMapper = mapperParser.parse(mapping); byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testXHTML.html"); @@ -86,7 +87,7 @@ public void testContentBackcompat() throws Exception { * test for https://github.com/elastic/elasticsearch-mapper-attachments/issues/179 */ public void testSimpleMappingsWithAllFields() throws Exception { - DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY).documentMapperParser(); + DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/simple/test-mapping-all-fields.json"); DocumentMapper docMapper = mapperParser.parse(mapping); byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testXHTML.html"); @@ -132,7 +133,7 @@ public void testMapperErrorWithDotTwoLevels169() throws Exception { .endObject(); byte[] mapping = mappingBuilder.bytes().toBytes(); - MapperService mapperService = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY); + MapperService mapperService = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); DocumentMapper docMapper = mapperService.parse("mail", new CompressedXContent(mapping), true); // this should not throw an exception mapperService.parse("mail", new CompressedXContent(docMapper.mapping().toString()), true); diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/StandaloneRunner.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/StandaloneRunner.java index 40c7f1d56d568..730172881fc5d 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/StandaloneRunner.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/StandaloneRunner.java @@ -32,7 +32,7 @@ import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.ParseContext; -import org.elasticsearch.mapper.attachments.AttachmentMapper; +import org.elasticsearch.index.mapper.core.MapperTestUtils; import java.io.FileNotFoundException; import java.io.IOException; @@ -86,7 +86,7 @@ protected TikaRunner(Terminal terminal, String url, Integer size, String base64t this.size = size; this.url = url; this.base64text = base64text; - DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(PathUtils.get("."), Settings.EMPTY).documentMapperParser(); // use CWD b/c it won't be used + DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(PathUtils.get("."), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); // use CWD b/c it won't be used String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/standalone/standalone-mapping.json"); docMapper = mapperParser.parse(mapping); diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/VariousDocTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/VariousDocTests.java index b427a1df95208..cc2a3dd999ee7 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/VariousDocTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/VariousDocTests.java @@ -26,7 +26,7 @@ import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.ParseContext; -import org.elasticsearch.mapper.attachments.AttachmentMapper; +import org.elasticsearch.index.mapper.core.MapperTestUtils; import org.junit.Before; import java.io.IOException; @@ -48,7 +48,7 @@ public class VariousDocTests extends AttachmentUnitTestCase { @Before public void createMapper() throws IOException { - DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY).documentMapperParser(); + DocumentMapperParser mapperParser = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY, AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()).documentMapperParser(); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/various-doc/test-mapping.json"); docMapper = mapperParser.parse(mapping); @@ -95,7 +95,7 @@ public void testTxtDocument() throws Exception { assertParseable("text-in-english.txt"); testMapper("text-in-english.txt", false); } - + /** * Test for .epub */ @@ -131,7 +131,7 @@ void assertException(String filename, String expectedMessage) throws Exception { protected void assertParseable(String filename) throws Exception { try (InputStream is = VariousDocTests.class.getResourceAsStream("/org/elasticsearch/index/mapper/attachment/test/sample-files/" + filename)) { byte bytes[] = IOUtils.toByteArray(is); - String parsedContent = TikaImpl.parse(bytes, new Metadata(), -1); + String parsedContent = TikaImpl.parse(bytes, new Metadata(), -1); assertThat(parsedContent, not(isEmptyOrNullString())); logger.debug("extracted content: {}", parsedContent); }