Search in sources :

Example 1 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class CodecTests method createCodecService.

private CodecService createCodecService() throws IOException {
    Settings nodeSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    IndexSettings settings = IndexSettingsModule.newIndexSettings("_na", nodeSettings);
    SimilarityService similarityService = new SimilarityService(settings, Collections.emptyMap());
    IndexAnalyzers indexAnalyzers = createTestAnalysis(settings, nodeSettings).indexAnalyzers;
    MapperRegistry mapperRegistry = new MapperRegistry(Collections.emptyMap(), Collections.emptyMap());
    MapperService service = new MapperService(settings, indexAnalyzers, xContentRegistry(), similarityService, mapperRegistry, () -> null);
    return new CodecService(service, ESLoggerFactory.getLogger("test"));
}
Also used : MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) IndexSettings(org.elasticsearch.index.IndexSettings) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) MapperService(org.elasticsearch.index.mapper.MapperService)

Example 2 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class ExternalFieldMapperTests method testExternalValuesWithMultifieldTwoLevels.

public void testExternalValuesWithMultifieldTwoLevels() throws Exception {
    Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    IndexService indexService = createIndex("test", settings);
    Map<String, Mapper.TypeParser> mapperParsers = new HashMap<>();
    mapperParsers.put(ExternalMapperPlugin.EXTERNAL, new ExternalMapper.TypeParser(ExternalMapperPlugin.EXTERNAL, "foo"));
    mapperParsers.put(ExternalMapperPlugin.EXTERNAL_BIS, new ExternalMapper.TypeParser(ExternalMapperPlugin.EXTERNAL, "bar"));
    mapperParsers.put(TextFieldMapper.CONTENT_TYPE, new TextFieldMapper.TypeParser());
    MapperRegistry mapperRegistry = new MapperRegistry(mapperParsers, Collections.emptyMap());
    Supplier<QueryShardContext> queryShardContext = () -> {
        return indexService.newQueryShardContext(0, null, () -> {
            throw new UnsupportedOperationException();
        });
    };
    DocumentMapperParser parser = new DocumentMapperParser(indexService.getIndexSettings(), indexService.mapperService(), indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
    DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", ExternalMapperPlugin.EXTERNAL).startObject("fields").startObject("field").field("type", "text").startObject("fields").startObject("generated").field("type", ExternalMapperPlugin.EXTERNAL_BIS).endObject().startObject("raw").field("type", "text").endObject().endObject().endObject().startObject("raw").field("type", "text").endObject().endObject().endObject().endObject().endObject().endObject().string()));
    ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "1234").endObject().bytes());
    assertThat(doc.rootDoc().getField("field.bool"), notNullValue());
    assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T"));
    assertThat(doc.rootDoc().getField("field.point"), notNullValue());
    assertThat(doc.rootDoc().getField("field.shape"), notNullValue());
    assertThat(doc.rootDoc().getField("field.field"), notNullValue());
    assertThat(doc.rootDoc().getField("field.field").stringValue(), is("foo"));
    assertThat(doc.rootDoc().getField("field.field.generated.generated"), notNullValue());
    assertThat(doc.rootDoc().getField("field.field.generated.generated").stringValue(), is("bar"));
    assertThat(doc.rootDoc().getField("field.field.raw"), notNullValue());
    assertThat(doc.rootDoc().getField("field.field.raw").stringValue(), is("foo"));
    assertThat(doc.rootDoc().getField("field.raw"), notNullValue());
    assertThat(doc.rootDoc().getField("field.raw").stringValue(), is("foo"));
}
Also used : IndexService(org.elasticsearch.index.IndexService) HashMap(java.util.HashMap) Version(org.elasticsearch.Version) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Settings(org.elasticsearch.common.settings.Settings)

Example 3 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class MetaDataIndexUpgradeServiceTests method testUpgrade.

public void testUpgrade() {
    MetaDataIndexUpgradeService service = new MetaDataIndexUpgradeService(Settings.EMPTY, xContentRegistry(), new MapperRegistry(Collections.emptyMap(), Collections.emptyMap()), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
    IndexMetaData src = newIndexMeta("foo", Settings.builder().put("index.refresh_interval", "-200").build());
    assertFalse(service.isUpgraded(src));
    src = service.upgradeIndexMetaData(src, Version.CURRENT.minimumIndexCompatibilityVersion());
    assertTrue(service.isUpgraded(src));
    assertEquals("-200", src.getSettings().get("archived.index.refresh_interval"));
    assertNull(src.getSettings().get("index.refresh_interval"));
    // no double upgrade
    assertSame(src, service.upgradeIndexMetaData(src, Version.CURRENT.minimumIndexCompatibilityVersion()));
}
Also used : MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry)

Example 4 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class MetaDataIndexUpgradeServiceTests method testFailUpgrade.

public void testFailUpgrade() {
    MetaDataIndexUpgradeService service = new MetaDataIndexUpgradeService(Settings.EMPTY, xContentRegistry(), new MapperRegistry(Collections.emptyMap(), Collections.emptyMap()), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
    final IndexMetaData metaData = newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_VERSION_UPGRADED, Version.V_5_0_0_beta1).put(IndexMetaData.SETTING_VERSION_CREATED, Version.fromString("2.4.0")).put(IndexMetaData.SETTING_VERSION_MINIMUM_COMPATIBLE, Version.CURRENT.luceneVersion.toString()).build());
    String message = expectThrows(IllegalStateException.class, () -> service.upgradeIndexMetaData(metaData, Version.CURRENT.minimumIndexCompatibilityVersion())).getMessage();
    assertEquals(message, "The index [[foo/BOOM]] was created with version [2.4.0] but the minimum compatible version is [5.0.0]." + " It should be re-indexed in Elasticsearch 5.x before upgrading to " + Version.CURRENT.toString() + ".");
    IndexMetaData goodMeta = newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_VERSION_UPGRADED, Version.V_5_0_0_beta1).put(IndexMetaData.SETTING_VERSION_CREATED, Version.fromString("5.1.0")).put(IndexMetaData.SETTING_VERSION_MINIMUM_COMPATIBLE, Version.CURRENT.luceneVersion.toString()).build());
    service.upgradeIndexMetaData(goodMeta, Version.V_5_0_0.minimumIndexCompatibilityVersion());
}
Also used : MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry)

Example 5 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class MetaDataIndexUpgradeServiceTests method testArchiveBrokenIndexSettings.

public void testArchiveBrokenIndexSettings() {
    MetaDataIndexUpgradeService service = new MetaDataIndexUpgradeService(Settings.EMPTY, xContentRegistry(), new MapperRegistry(Collections.emptyMap(), Collections.emptyMap()), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
    IndexMetaData src = newIndexMeta("foo", Settings.EMPTY);
    IndexMetaData indexMetaData = service.archiveBrokenIndexSettings(src);
    assertSame(indexMetaData, src);
    src = newIndexMeta("foo", Settings.builder().put("index.refresh_interval", "-200").build());
    indexMetaData = service.archiveBrokenIndexSettings(src);
    assertNotSame(indexMetaData, src);
    assertEquals("-200", indexMetaData.getSettings().get("archived.index.refresh_interval"));
    src = newIndexMeta("foo", Settings.builder().put("index.codec", "best_compression1").build());
    indexMetaData = service.archiveBrokenIndexSettings(src);
    assertNotSame(indexMetaData, src);
    assertEquals("best_compression1", indexMetaData.getSettings().get("archived.index.codec"));
    src = newIndexMeta("foo", Settings.builder().put("index.refresh.interval", "-1").build());
    indexMetaData = service.archiveBrokenIndexSettings(src);
    assertNotSame(indexMetaData, src);
    assertEquals("-1", indexMetaData.getSettings().get("archived.index.refresh.interval"));
    // double archive?
    src = newIndexMeta("foo", indexMetaData.getSettings());
    indexMetaData = service.archiveBrokenIndexSettings(src);
    assertSame(indexMetaData, src);
}
Also used : MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry)

Aggregations

MapperRegistry (org.elasticsearch.indices.mapper.MapperRegistry)12 Settings (org.elasticsearch.common.settings.Settings)5 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)5 Version (org.elasticsearch.Version)4 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)4 IndexService (org.elasticsearch.index.IndexService)4 HashMap (java.util.HashMap)2 IndexableField (org.apache.lucene.index.IndexableField)2 GeoPoint (org.elasticsearch.common.geo.GeoPoint)2 IndexAnalyzers (org.elasticsearch.index.analysis.IndexAnalyzers)2 MapperService (org.elasticsearch.index.mapper.MapperService)2 SimilarityService (org.elasticsearch.index.similarity.SimilarityService)2 BytesRef (org.apache.lucene.util.BytesRef)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 IndexSettings (org.elasticsearch.index.IndexSettings)1 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)1 IndicesModule (org.elasticsearch.indices.IndicesModule)1 Before (org.junit.Before)1