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);
}
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);
}
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);
}
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.");
}
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());
}
Aggregations