Search in sources :

Example 16 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testDisableQueryCacheHasPrecedenceOverForceQueryCache.

public void testDisableQueryCacheHasPrecedenceOverForceQueryCache() throws IOException {
    Settings indexSettings = Settings.builder().put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), false).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.forceQueryCacheProvider((a, b) -> new CustomQueryCache());
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.cache().query() instanceof DisabledQueryCache);
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache)

Example 17 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testForceCustomQueryCache.

public void testForceCustomQueryCache() throws IOException {
    Settings indexSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.forceQueryCacheProvider((a, b) -> new CustomQueryCache());
    expectThrows(AlreadySetException.class, () -> module.forceQueryCacheProvider((a, b) -> new CustomQueryCache()));
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.cache().query() instanceof CustomQueryCache);
    indexService.close("simon says", false);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Property(org.elasticsearch.common.settings.Setting.Property) BigArrays(org.elasticsearch.common.util.BigArrays) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) IndexSettingsModule(org.elasticsearch.test.IndexSettingsModule) Environment(org.elasticsearch.env.Environment) Term(org.apache.lucene.index.Term) IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) AssertingDirectoryReader(org.apache.lucene.index.AssertingDirectoryReader) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry) Settings(org.elasticsearch.common.settings.Settings) SearchOperationListener(org.elasticsearch.index.shard.SearchOperationListener) ThreadPool(org.elasticsearch.threadpool.ThreadPool) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) AlreadySetException(org.apache.lucene.util.SetOnce.AlreadySetException) TestSearchContext(org.elasticsearch.test.TestSearchContext) Setting(org.elasticsearch.common.settings.Setting) IndexStore(org.elasticsearch.index.store.IndexStore) Collections.emptyList(java.util.Collections.emptyList) DirectoryReader(org.apache.lucene.index.DirectoryReader) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Engine(org.elasticsearch.index.engine.Engine) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) FieldInvertState(org.apache.lucene.index.FieldInvertState) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) SimilarityProvider(org.elasticsearch.index.similarity.SimilarityProvider) IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) IndexSearcher(org.apache.lucene.search.IndexSearcher) InternalEngineTests(org.elasticsearch.index.engine.InternalEngineTests) ResourceWatcherService(org.elasticsearch.watcher.ResourceWatcherService) Weight(org.apache.lucene.search.Weight) ClusterService(org.elasticsearch.cluster.service.ClusterService) SearchContext(org.elasticsearch.search.internal.SearchContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) ScriptSettings(org.elasticsearch.script.ScriptSettings) IndexRemovalReason(org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason) MockEngineFactory(org.elasticsearch.test.engine.MockEngineFactory) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) IndexSearcherWrapper(org.elasticsearch.index.shard.IndexSearcherWrapper) Similarity(org.apache.lucene.search.similarities.Similarity) IndicesModule(org.elasticsearch.indices.IndicesModule) ESTestCase(org.elasticsearch.test.ESTestCase) TermStatistics(org.apache.lucene.search.TermStatistics) EngineException(org.elasticsearch.index.engine.EngineException) Collections.emptyMap(java.util.Collections.emptyMap) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) ShardLock(org.elasticsearch.env.ShardLock) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) TimeUnit(java.util.concurrent.TimeUnit) CollectionStatistics(org.apache.lucene.search.CollectionStatistics) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) QueryCache(org.elasticsearch.index.cache.query.QueryCache) ClusterServiceUtils(org.elasticsearch.test.ClusterServiceUtils) ScriptService(org.elasticsearch.script.ScriptService) Collections(java.util.Collections) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings)

Example 18 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testAddSimilarity.

public void testAddSimilarity() throws IOException {
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.similarity.my_similarity.type", "test_similarity").put("index.similarity.my_similarity.key", "there is a key").put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.addSimilarity("test_similarity", (string, providerSettings, indexLevelSettings) -> new SimilarityProvider() {

        @Override
        public String name() {
            return string;
        }

        @Override
        public Similarity get() {
            return new TestSimilarity(providerSettings.get("key"));
        }
    });
    IndexService indexService = newIndexService(module);
    SimilarityService similarityService = indexService.similarityService();
    assertNotNull(similarityService.getSimilarity("my_similarity"));
    assertTrue(similarityService.getSimilarity("my_similarity").get() instanceof TestSimilarity);
    assertEquals("my_similarity", similarityService.getSimilarity("my_similarity").name());
    assertEquals("there is a key", ((TestSimilarity) similarityService.getSimilarity("my_similarity").get()).key);
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) SimilarityProvider(org.elasticsearch.index.similarity.SimilarityProvider) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) Similarity(org.apache.lucene.search.similarities.Similarity) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings)

Example 19 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class AnalysisModuleTests method testAnalyzerAlias.

public void testAnalyzerAlias() throws IOException {
    Settings settings = Settings.builder().put("index.analysis.analyzer.foobar.alias", "default").put("index.analysis.analyzer.foobar.type", "keyword").put("index.analysis.analyzer.foobar_search.alias", "default_search").put("index.analysis.analyzer.foobar_search.type", "english").put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_5)).build();
    AnalysisRegistry newRegistry = getNewRegistry(settings);
    IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings);
    assertThat(indexAnalyzers.get("default").analyzer(), is(instanceOf(KeywordAnalyzer.class)));
    assertThat(indexAnalyzers.get("default_search").analyzer(), is(instanceOf(EnglishAnalyzer.class)));
    assertWarnings("setting [index.analysis.analyzer.foobar.alias] is only allowed on index [test] because it was created before " + "5.x; analyzer aliases can no longer be created on new indices.", "setting [index.analysis.analyzer.foobar_search.alias] is only allowed on index [test] because it was created before " + "5.x; analyzer aliases can no longer be created on new indices.");
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 20 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class AnalysisModuleTests method testAnalyzerAliasNotAllowedPost5x.

public void testAnalyzerAliasNotAllowedPost5x() throws IOException {
    Settings settings = Settings.builder().put("index.analysis.analyzer.foobar.type", "standard").put("index.analysis.analyzer.foobar.alias", "foobaz").put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_5_0_0_beta1, null)).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    AnalysisRegistry registry = getNewRegistry(settings);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> getIndexAnalyzers(registry, settings));
    assertEquals("setting [index.analysis.analyzer.foobar.alias] is not supported", e.getMessage());
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Aggregations

AnalysisRegistry (org.elasticsearch.index.analysis.AnalysisRegistry)21 Settings (org.elasticsearch.common.settings.Settings)13 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 IndexSettings (org.elasticsearch.index.IndexSettings)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IOException (java.io.IOException)4 IndexAnalyzers (org.elasticsearch.index.analysis.IndexAnalyzers)4 AlreadySetException (org.apache.lucene.util.SetOnce.AlreadySetException)3 EngineException (org.elasticsearch.index.engine.EngineException)3 AssertingDirectoryReader (org.apache.lucene.index.AssertingDirectoryReader)2 Term (org.apache.lucene.index.Term)2 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)2 Similarity (org.apache.lucene.search.similarities.Similarity)2 Environment (org.elasticsearch.env.Environment)2 NamedAnalyzer (org.elasticsearch.index.analysis.NamedAnalyzer)2 DisabledQueryCache (org.elasticsearch.index.cache.query.DisabledQueryCache)2 Engine (org.elasticsearch.index.engine.Engine)2 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)2 IndexingOperationListener (org.elasticsearch.index.shard.IndexingOperationListener)2 ShardId (org.elasticsearch.index.shard.ShardId)2