use of org.opensearch.indices.mapper.MapperRegistry in project OpenSearch by opensearch-project.
the class MapperServiceTestCase method createMapperService.
/**
* Create a {@link MapperService} like we would for an index.
*/
protected final MapperService createMapperService(Version version, XContentBuilder mapping) throws IOException {
IndexMetadata meta = IndexMetadata.builder("index").settings(Settings.builder().put("index.version.created", version)).numberOfReplicas(0).numberOfShards(1).build();
IndexSettings indexSettings = new IndexSettings(meta, getIndexSettings());
MapperRegistry mapperRegistry = new IndicesModule(getPlugins().stream().filter(p -> p instanceof MapperPlugin).map(p -> (MapperPlugin) p).collect(toList())).getMapperRegistry();
ScriptModule scriptModule = new ScriptModule(Settings.EMPTY, getPlugins().stream().filter(p -> p instanceof ScriptPlugin).map(p -> (ScriptPlugin) p).collect(toList()));
ScriptService scriptService = new ScriptService(getIndexSettings(), scriptModule.engines, scriptModule.contexts);
SimilarityService similarityService = new SimilarityService(indexSettings, scriptService, emptyMap());
MapperService mapperService = new MapperService(indexSettings, createIndexAnalyzers(indexSettings), xContentRegistry(), similarityService, mapperRegistry, () -> {
throw new UnsupportedOperationException();
}, () -> true, scriptService);
merge(mapperService, mapping);
return mapperService;
}
use of org.opensearch.indices.mapper.MapperRegistry in project OpenSearch by opensearch-project.
the class MapperTestUtils method newMapperService.
public static MapperService newMapperService(NamedXContentRegistry xContentRegistry, Path tempDir, Settings settings, IndicesModule indicesModule, String indexName) throws IOException {
Settings.Builder settingsBuilder = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), tempDir).put(settings);
if (settings.get(IndexMetadata.SETTING_VERSION_CREATED) == null) {
settingsBuilder.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT);
}
Settings finalSettings = settingsBuilder.build();
MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexName, finalSettings);
IndexAnalyzers indexAnalyzers = createTestAnalysis(indexSettings, finalSettings).indexAnalyzers;
SimilarityService similarityService = new SimilarityService(indexSettings, null, Collections.emptyMap());
return new MapperService(indexSettings, indexAnalyzers, xContentRegistry, similarityService, mapperRegistry, () -> null, () -> false, null);
}
use of org.opensearch.indices.mapper.MapperRegistry in project OpenSearch by opensearch-project.
the class IndicesModuleTests method testNoOpFieldPredicate.
public void testNoOpFieldPredicate() {
List<MapperPlugin> mapperPlugins = Arrays.asList(new MapperPlugin() {
@Override
public Function<String, Predicate<String>> getFieldFilter() {
return MapperPlugin.NOOP_FIELD_FILTER;
}
}, new MapperPlugin() {
@Override
public Function<String, Predicate<String>> getFieldFilter() {
return index -> index.equals("hidden_index") ? field -> false : MapperPlugin.NOOP_FIELD_PREDICATE;
}
}, new MapperPlugin() {
@Override
public Function<String, Predicate<String>> getFieldFilter() {
return index -> index.equals("filtered") ? field -> field.equals("visible") : MapperPlugin.NOOP_FIELD_PREDICATE;
}
});
IndicesModule indicesModule = new IndicesModule(mapperPlugins);
MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
Function<String, Predicate<String>> fieldFilter = mapperRegistry.getFieldFilter();
assertSame(MapperPlugin.NOOP_FIELD_PREDICATE, fieldFilter.apply(randomAlphaOfLengthBetween(3, 7)));
assertNotSame(MapperPlugin.NOOP_FIELD_PREDICATE, fieldFilter.apply("hidden_index"));
assertNotSame(MapperPlugin.NOOP_FIELD_PREDICATE, fieldFilter.apply("filtered"));
}
Aggregations