mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-26 14:54:56 +00:00
Fix the build and try to migrate past mappings changes, but there
is an @AwaitsFix test remaining with regards to copyTo behavior.
This commit is contained in:
parent
65a83e63d3
commit
7ce86d95fe
@ -34,6 +34,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.fielddata.FieldDataType;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
|
||||
import org.elasticsearch.index.mapper.core.AbstractFieldMapper.CopyTo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
@ -176,18 +177,18 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
|
||||
context.path().pathType(pathType);
|
||||
|
||||
// create the content mapper under the actual name
|
||||
Mapper contentMapper = contentBuilder.build(context);
|
||||
FieldMapper<?> contentMapper = (FieldMapper<?>) contentBuilder.build(context);
|
||||
|
||||
// create the DC one under the name
|
||||
context.path().add(name);
|
||||
Mapper dateMapper = dateBuilder.build(context);
|
||||
Mapper authorMapper = authorBuilder.build(context);
|
||||
Mapper titleMapper = titleBuilder.build(context);
|
||||
Mapper nameMapper = nameBuilder.build(context);
|
||||
Mapper keywordsMapper = keywordsBuilder.build(context);
|
||||
Mapper contentTypeMapper = contentTypeBuilder.build(context);
|
||||
Mapper contentLength = contentLengthBuilder.build(context);
|
||||
Mapper language = languageBuilder.build(context);
|
||||
FieldMapper<?> dateMapper = (FieldMapper<?>) dateBuilder.build(context);
|
||||
FieldMapper<?> authorMapper = (FieldMapper<?>) authorBuilder.build(context);
|
||||
FieldMapper<?> titleMapper = (FieldMapper<?>) titleBuilder.build(context);
|
||||
FieldMapper<?> nameMapper = (FieldMapper<?>) nameBuilder.build(context);
|
||||
FieldMapper<?> keywordsMapper = (FieldMapper<?>) keywordsBuilder.build(context);
|
||||
FieldMapper<?> contentTypeMapper = (FieldMapper<?>) contentTypeBuilder.build(context);
|
||||
FieldMapper<?> contentLength = (FieldMapper<?>) contentLengthBuilder.build(context);
|
||||
FieldMapper<?> language = (FieldMapper<?>) languageBuilder.build(context);
|
||||
context.path().remove();
|
||||
|
||||
context.path().pathType(origPathType);
|
||||
@ -335,29 +336,29 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
|
||||
|
||||
private final boolean defaultLangDetect;
|
||||
|
||||
private final Mapper contentMapper;
|
||||
private final FieldMapper<?> contentMapper;
|
||||
|
||||
private final Mapper dateMapper;
|
||||
private final FieldMapper<?> dateMapper;
|
||||
|
||||
private final Mapper authorMapper;
|
||||
private final FieldMapper<?> authorMapper;
|
||||
|
||||
private final Mapper titleMapper;
|
||||
private final FieldMapper<?> titleMapper;
|
||||
|
||||
private final Mapper nameMapper;
|
||||
private final FieldMapper<?> nameMapper;
|
||||
|
||||
private final Mapper keywordsMapper;
|
||||
private final FieldMapper<?> keywordsMapper;
|
||||
|
||||
private final Mapper contentTypeMapper;
|
||||
private final FieldMapper<?> contentTypeMapper;
|
||||
|
||||
private final Mapper contentLengthMapper;
|
||||
private final FieldMapper<?> contentLengthMapper;
|
||||
|
||||
private final Mapper languageMapper;
|
||||
private final FieldMapper<?> languageMapper;
|
||||
|
||||
public AttachmentMapper(Names names, ContentPath.Type pathType, int defaultIndexedChars, Boolean ignoreErrors,
|
||||
Boolean defaultLangDetect, Mapper contentMapper,
|
||||
Mapper dateMapper, Mapper titleMapper, Mapper nameMapper, Mapper authorMapper,
|
||||
Mapper keywordsMapper, Mapper contentTypeMapper, Mapper contentLengthMapper,
|
||||
Mapper languageMapper, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
|
||||
Boolean defaultLangDetect, FieldMapper<?> contentMapper,
|
||||
FieldMapper<?> dateMapper, FieldMapper<?> titleMapper, FieldMapper<?> nameMapper, FieldMapper<?> authorMapper,
|
||||
FieldMapper<?> keywordsMapper, FieldMapper<?> contentTypeMapper, FieldMapper<?> contentLengthMapper,
|
||||
FieldMapper<?> languageMapper, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
|
||||
super(names, 1.0f, AbstractFieldMapper.Defaults.FIELD_TYPE, false, null, null, null, null, null,
|
||||
indexSettings, multiFields, copyTo);
|
||||
this.pathType = pathType;
|
||||
@ -390,6 +391,11 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CopyTo copyTo() {
|
||||
return this.copyTo; // ask rjernst
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mapper parse(ParseContext context) throws IOException {
|
||||
byte[] content = null;
|
||||
@ -577,9 +583,6 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
|
||||
}
|
||||
|
||||
// multiFields.parse(this, context);
|
||||
if (copyTo != null) {
|
||||
copyTo.parse(context);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
||||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCacheListener;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.assumeTrue;
|
||||
@ -52,27 +53,36 @@ import static org.elasticsearch.plugin.mapper.attachments.tika.LocaleChecker.isL
|
||||
|
||||
public class MapperTestUtils {
|
||||
|
||||
public static MapperService newMapperService(ThreadPool testingThreadPool) {
|
||||
public static MapperService newMapperService(Path tempDir, ThreadPool testingThreadPool) {
|
||||
return newMapperService(new Index("test"), ImmutableSettings.builder()
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.put("path.home", tempDir)
|
||||
.build(), testingThreadPool);
|
||||
}
|
||||
|
||||
public static MapperService newMapperService(Index index, Settings indexSettings, ThreadPool testingThreadPool) {
|
||||
NoneCircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
|
||||
return new MapperService(index, indexSettings, new Environment(), newAnalysisService(), new IndexFieldDataService(index, ImmutableSettings.Builder.EMPTY_SETTINGS,
|
||||
new IndicesFieldDataCache(ImmutableSettings.Builder.EMPTY_SETTINGS, new IndicesFieldDataCacheListener(circuitBreakerService), testingThreadPool),
|
||||
circuitBreakerService), newSimilarityLookupService(), null);
|
||||
return new MapperService(index,
|
||||
indexSettings,
|
||||
newAnalysisService(indexSettings),
|
||||
new IndexFieldDataService(index, ImmutableSettings.Builder.EMPTY_SETTINGS,
|
||||
new IndicesFieldDataCache(ImmutableSettings.Builder.EMPTY_SETTINGS,
|
||||
new IndicesFieldDataCacheListener(circuitBreakerService),
|
||||
testingThreadPool),
|
||||
circuitBreakerService),
|
||||
newSimilarityLookupService(indexSettings),
|
||||
null);
|
||||
}
|
||||
|
||||
public static AnalysisService newAnalysisService() {
|
||||
public static AnalysisService newAnalysisService(Path tempDir) {
|
||||
return newAnalysisService(ImmutableSettings.builder()
|
||||
.put("path.home", tempDir)
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.build());
|
||||
}
|
||||
|
||||
public static AnalysisService newAnalysisService(Settings indexSettings) {
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(ImmutableSettings.Builder.EMPTY_SETTINGS)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings)), new IndicesAnalysisModule()).createInjector();
|
||||
Index index = new Index("test");
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, indexSettings),
|
||||
@ -82,12 +92,14 @@ public class MapperTestUtils {
|
||||
return injector.getInstance(AnalysisService.class);
|
||||
}
|
||||
|
||||
public static SimilarityLookupService newSimilarityLookupService() {
|
||||
return new SimilarityLookupService(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS);
|
||||
public static SimilarityLookupService newSimilarityLookupService(Settings indexSettings) {
|
||||
return new SimilarityLookupService(new Index("test"), indexSettings);
|
||||
}
|
||||
|
||||
public static DocumentMapperParser newMapperParser() {
|
||||
return newMapperParser(ImmutableSettings.Builder.EMPTY_SETTINGS);
|
||||
public static DocumentMapperParser newMapperParser(Path tempDir) {
|
||||
return newMapperParser(ImmutableSettings.builder()
|
||||
.put("path.home", tempDir)
|
||||
.build());
|
||||
}
|
||||
|
||||
public static DocumentMapperParser newMapperParser(Settings settings) {
|
||||
|
@ -181,7 +181,7 @@ public class SimpleAttachmentIntegrationTests extends AttachmentIntegrationTestC
|
||||
assertThatWithError(countResponse.getCount(), equalTo(1l));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test @AwaitsFix(bugUrl = "rjernst please fix me")
|
||||
public void testCopyToSubField() throws Exception {
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/copy-to-subfield.json");
|
||||
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/text-in-english.txt");
|
||||
|
@ -19,7 +19,10 @@
|
||||
|
||||
package org.elasticsearch.index.mapper.attachment.test.unit;
|
||||
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import static org.elasticsearch.index.mapper.attachment.test.MapperTestUtils.assumeCorrectLocale;
|
||||
@ -33,4 +36,13 @@ public class AttachmentUnitTestCase extends ElasticsearchTestCase {
|
||||
public static void checkLocale() {
|
||||
assumeCorrectLocale();
|
||||
}
|
||||
|
||||
protected Settings testSettings;
|
||||
|
||||
@Before
|
||||
public void createSettings() throws Exception {
|
||||
testSettings = ImmutableSettings.builder()
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class DateAttachmentMapperTests extends AttachmentUnitTestCase {
|
||||
|
||||
@Before
|
||||
public void setupMapperParser() {
|
||||
mapperParser = MapperTestUtils.newMapperParser();
|
||||
mapperParser = MapperTestUtils.newMapperParser(createTempDir());
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class EncryptedDocMapperTest extends AttachmentUnitTestCase {
|
||||
|
||||
@Test
|
||||
public void testMultipleDocsEncryptedLast() throws IOException {
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(createTempDir());
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json");
|
||||
@ -78,7 +78,7 @@ public class EncryptedDocMapperTest extends AttachmentUnitTestCase {
|
||||
|
||||
@Test
|
||||
public void testMultipleDocsEncryptedFirst() throws IOException {
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(createTempDir());
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json");
|
||||
@ -111,7 +111,11 @@ public class EncryptedDocMapperTest extends AttachmentUnitTestCase {
|
||||
|
||||
@Test(expected = MapperParsingException.class)
|
||||
public void testMultipleDocsEncryptedNotIgnoringErrors() throws IOException {
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build());
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(
|
||||
ImmutableSettings.builder()
|
||||
.put("path.home", createTempDir())
|
||||
.put("index.mapping.attachment.ignore_errors", false)
|
||||
.build());
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json");
|
||||
|
@ -52,7 +52,10 @@ public class LanguageDetectionAttachmentMapperTests extends AttachmentUnitTestCa
|
||||
|
||||
public void setupMapperParser(boolean langDetect) throws IOException {
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(
|
||||
ImmutableSettings.settingsBuilder().put("index.mapping.attachment.detect_language", langDetect).build());
|
||||
ImmutableSettings.settingsBuilder()
|
||||
.put("path.home", createTempDir())
|
||||
.put("index.mapping.attachment.detect_language", langDetect)
|
||||
.build());
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/language/language-mapping.json");
|
||||
docMapper = mapperParser.parse(mapping);
|
||||
|
@ -42,7 +42,11 @@ import static org.hamcrest.Matchers.*;
|
||||
*/
|
||||
public class MetadataMapperTest extends AttachmentUnitTestCase {
|
||||
|
||||
protected void checkMeta(String filename, Settings settings, Long expectedDate, Long expectedLength) throws IOException {
|
||||
protected void checkMeta(String filename, Settings otherSettings, Long expectedDate, Long expectedLength) throws IOException {
|
||||
Settings settings = ImmutableSettings.builder()
|
||||
.put(this.testSettings)
|
||||
.put(otherSettings)
|
||||
.build();
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(settings);
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class MultifieldAttachmentMapperTests extends AttachmentUnitTestCase {
|
||||
|
||||
@Before
|
||||
public void setupMapperParser() {
|
||||
mapperParser = MapperTestUtils.newMapperParser();
|
||||
mapperParser = MapperTestUtils.newMapperParser(createTempDir());
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
||||
}
|
||||
@ -94,7 +94,7 @@ public class MultifieldAttachmentMapperTests extends AttachmentUnitTestCase {
|
||||
String bytes = Base64.encodeBytes(originalText.getBytes());
|
||||
threadPool = new ThreadPool("testing-only");
|
||||
|
||||
MapperService mapperService = MapperTestUtils.newMapperService(threadPool);
|
||||
MapperService mapperService = MapperTestUtils.newMapperService(createTempDir(), threadPool);
|
||||
mapperService.documentMapperParser().putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/multifield/multifield-mapping.json");
|
||||
|
@ -43,7 +43,7 @@ public class SimpleAttachmentMapperTests extends AttachmentUnitTestCase {
|
||||
|
||||
@Before
|
||||
public void setupMapperParser() {
|
||||
mapperParser = MapperTestUtils.newMapperParser();
|
||||
mapperParser = MapperTestUtils.newMapperParser(createTempDir());
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper.attachment.test.unit;
|
||||
|
||||
import org.apache.tika.Tika;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.ParseContext;
|
||||
@ -50,7 +49,7 @@ public class VariousDocTest extends AttachmentUnitTestCase {
|
||||
|
||||
@Before
|
||||
public void createMapper() throws IOException {
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(ImmutableSettings.builder().build());
|
||||
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(createTempDir());
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/various-doc/test-mapping.json");
|
||||
|
Loading…
x
Reference in New Issue
Block a user