Search in sources :

Example 1 with ScriptModule

use of org.opensearch.script.ScriptModule 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;
}
Also used : IndicesModule(org.opensearch.indices.IndicesModule) BytesReference(org.opensearch.common.bytes.BytesReference) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ScriptModule(org.opensearch.script.ScriptModule) SimilarityService(org.opensearch.index.similarity.SimilarityService) ToXContent(org.opensearch.common.xcontent.ToXContent) CheckedConsumer(org.opensearch.common.CheckedConsumer) CompressedXContent(org.opensearch.common.compress.CompressedXContent) MapperPlugin(org.opensearch.plugins.MapperPlugin) Version(org.opensearch.Version) AnalyzerScope(org.opensearch.index.analysis.AnalyzerScope) MapperRegistry(org.opensearch.indices.mapper.MapperRegistry) Directory(org.apache.lucene.store.Directory) XContentFactory(org.opensearch.common.xcontent.XContentFactory) Collections.singletonMap(java.util.Collections.singletonMap) Mockito.anyString(org.mockito.Mockito.anyString) ScriptService(org.opensearch.script.ScriptService) Collections.emptyMap(java.util.Collections.emptyMap) NamedAnalyzer(org.opensearch.index.analysis.NamedAnalyzer) ScriptPlugin(org.opensearch.plugins.ScriptPlugin) Collections.emptyList(java.util.Collections.emptyList) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Collection(java.util.Collection) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Plugin(org.opensearch.plugins.Plugin) SearchLookup(org.opensearch.search.lookup.SearchLookup) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) Collectors.toList(java.util.stream.Collectors.toList) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) BytesArray(org.opensearch.common.bytes.BytesArray) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) IndexSettings(org.opensearch.index.IndexSettings) QueryShardContext(org.opensearch.index.query.QueryShardContext) XContentType(org.opensearch.common.xcontent.XContentType) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Mockito.any(org.mockito.Mockito.any) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Collections(java.util.Collections) IndexReader(org.apache.lucene.index.IndexReader) IndexAnalyzers(org.opensearch.index.analysis.IndexAnalyzers) Mockito.mock(org.mockito.Mockito.mock) ScriptService(org.opensearch.script.ScriptService) ScriptModule(org.opensearch.script.ScriptModule) IndicesModule(org.opensearch.indices.IndicesModule) MapperRegistry(org.opensearch.indices.mapper.MapperRegistry) MapperPlugin(org.opensearch.plugins.MapperPlugin) IndexSettings(org.opensearch.index.IndexSettings) SimilarityService(org.opensearch.index.similarity.SimilarityService) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ScriptPlugin(org.opensearch.plugins.ScriptPlugin)

Aggregations

IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Collectors.toList (java.util.stream.Collectors.toList)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)1 Directory (org.apache.lucene.store.Directory)1 Mockito.any (org.mockito.Mockito.any)1 Mockito.anyString (org.mockito.Mockito.anyString)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 Version (org.opensearch.Version)1 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)1 CheckedConsumer (org.opensearch.common.CheckedConsumer)1 BytesArray (org.opensearch.common.bytes.BytesArray)1