Search in sources :

Example 6 with AnalysisRegistry

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

the class IndexModuleTests method testDefaultQueryCacheImplIsSelected.

public void testDefaultQueryCacheImplIsSelected() 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()));
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.cache().query() instanceof IndexQueryCache);
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings)

Example 7 with AnalysisRegistry

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

the class IndexModuleTests method testAddSearchOperationListener.

public void testAddSearchOperationListener() throws IOException {
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings(index, settings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    AtomicBoolean executed = new AtomicBoolean(false);
    SearchOperationListener listener = new SearchOperationListener() {

        @Override
        public void onNewContext(SearchContext context) {
            executed.set(true);
        }
    };
    module.addSearchOperationListener(listener);
    expectThrows(IllegalArgumentException.class, () -> module.addSearchOperationListener(listener));
    expectThrows(IllegalArgumentException.class, () -> module.addSearchOperationListener(null));
    IndexService indexService = newIndexService(module);
    assertEquals(2, indexService.getSearchOperationListener().size());
    assertEquals(SearchSlowLog.class, indexService.getSearchOperationListener().get(0).getClass());
    assertSame(listener, indexService.getSearchOperationListener().get(1));
    for (SearchOperationListener l : indexService.getSearchOperationListener()) {
        l.onNewContext(new TestSearchContext(null));
    }
    assertTrue(executed.get());
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestSearchContext(org.elasticsearch.test.TestSearchContext) TestSearchContext(org.elasticsearch.test.TestSearchContext) SearchContext(org.elasticsearch.search.internal.SearchContext) SearchOperationListener(org.elasticsearch.index.shard.SearchOperationListener)

Example 8 with AnalysisRegistry

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

the class IndexModuleTests method testRegisterIndexStore.

public void testRegisterIndexStore() throws IOException {
    final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "foo_store").build();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
    IndexModule module = new IndexModule(indexSettings, new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.addIndexStore("foo_store", FooStore::new);
    try {
        module.addIndexStore("foo_store", FooStore::new);
        fail("already registered");
    } catch (IllegalArgumentException ex) {
    // fine
    }
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.getIndexStore() instanceof FooStore);
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings)

Example 9 with AnalysisRegistry

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

the class AnalysisModuleTests method testAnalyzerAliasReferencesAlias.

public void testAnalyzerAliasReferencesAlias() throws IOException {
    Settings settings = Settings.builder().put("index.analysis.analyzer.foobar.alias", "default").put("index.analysis.analyzer.foobar.type", "german").put("index.analysis.analyzer.foobar_search.alias", "default_search").put("index.analysis.analyzer.foobar_search.type", "default").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(GermanAnalyzer.class)));
    // analyzer types are bound early before we resolve aliases
    assertThat(indexAnalyzers.get("default_search").analyzer(), is(instanceOf(StandardAnalyzer.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 10 with AnalysisRegistry

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

the class AnalysisModuleTests method testAnalyzerAliasMoreThanOnce.

public void testAnalyzerAliasMoreThanOnce() throws IOException {
    Settings settings = Settings.builder().put("index.analysis.analyzer.foobar.alias", "default").put("index.analysis.analyzer.foobar.type", "keyword").put("index.analysis.analyzer.foobar1.alias", "default").put("index.analysis.analyzer.foobar1.type", "english").put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_5)).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    AnalysisRegistry newRegistry = getNewRegistry(settings);
    IllegalStateException ise = expectThrows(IllegalStateException.class, () -> getIndexAnalyzers(newRegistry, settings));
    assertEquals("alias [default] is already used by [foobar]", ise.getMessage());
    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.foobar1.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) 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