Search in sources :

Example 66 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class TransportAnalyzeActionTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).put("index.analysis.filter.wordDelimiter.type", "word_delimiter").put("index.analysis.filter.wordDelimiter.split_on_numerics", false).put("index.analysis.analyzer.custom_analyzer.tokenizer", "whitespace").putArray("index.analysis.analyzer.custom_analyzer.filter", "lowercase", "wordDelimiter").put("index.analysis.analyzer.custom_analyzer.tokenizer", "whitespace").putArray("index.analysis.analyzer.custom_analyzer.filter", "lowercase", "wordDelimiter").put("index.analysis.tokenizer.trigram.type", "ngram").put("index.analysis.tokenizer.trigram.min_gram", 3).put("index.analysis.tokenizer.trigram.max_gram", 3).put("index.analysis.filter.synonym.type", "synonym").putArray("index.analysis.filter.synonym.synonyms", "kimchy => shay").put("index.analysis.filter.synonym.tokenizer", "trigram").put("index.analysis.filter.synonym.min_gram", 3).put("index.analysis.filter.synonym.max_gram", 3).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings);
    environment = new Environment(settings);
    registry = new AnalysisModule(environment, emptyList()).getAnalysisRegistry();
    indexAnalyzers = registry.build(idxSettings);
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Environment(org.elasticsearch.env.Environment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 67 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class KeyStoreCommandTestCase method setupEnv.

void setupEnv(boolean posix) throws IOException {
    final Configuration configuration;
    if (posix) {
        configuration = Configuration.unix().toBuilder().setAttributeViews("basic", "owner", "posix", "unix").build();
    } else {
        configuration = Configuration.unix();
    }
    FileSystem fs = Jimfs.newFileSystem(configuration);
    fileSystems.add(fs);
    // restored by restoreFileSystem in ESTestCase
    PathUtilsForTesting.installMock(fs);
    Path home = fs.getPath("/", "test-home");
    Files.createDirectories(home.resolve("config"));
    env = new Environment(Settings.builder().put("path.home", home).build());
}
Also used : Path(java.nio.file.Path) Configuration(com.google.common.jimfs.Configuration) FileSystem(java.nio.file.FileSystem) Environment(org.elasticsearch.env.Environment)

Example 68 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class AnalysisRegistryTests method testConfigureCamelCaseTokenFilter.

public void testConfigureCamelCaseTokenFilter() throws IOException {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.analysis.filter.wordDelimiter.type", "word_delimiter").put("index.analysis.filter.wordDelimiter.split_on_numerics", false).put("index.analysis.analyzer.custom_analyzer.tokenizer", "whitespace").putArray("index.analysis.analyzer.custom_analyzer.filter", "lowercase", "wordDelimiter").put("index.analysis.analyzer.custom_analyzer_1.tokenizer", "whitespace").putArray("index.analysis.analyzer.custom_analyzer_1.filter", "lowercase", "word_delimiter").build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings);
    IndexAnalyzers indexAnalyzers = new AnalysisModule(new Environment(settings), emptyList()).getAnalysisRegistry().build(idxSettings);
    try (NamedAnalyzer custom_analyser = indexAnalyzers.get("custom_analyzer")) {
        assertNotNull(custom_analyser);
        TokenStream tokenStream = custom_analyser.tokenStream("foo", "J2SE j2ee");
        tokenStream.reset();
        CharTermAttribute charTermAttribute = tokenStream.addAttribute(CharTermAttribute.class);
        List<String> token = new ArrayList<>();
        while (tokenStream.incrementToken()) {
            token.add(charTermAttribute.toString());
        }
        assertEquals(token.toString(), 2, token.size());
        assertEquals("j2se", token.get(0));
        assertEquals("j2ee", token.get(1));
    }
    try (NamedAnalyzer custom_analyser = indexAnalyzers.get("custom_analyzer_1")) {
        assertNotNull(custom_analyser);
        TokenStream tokenStream = custom_analyser.tokenStream("foo", "J2SE j2ee");
        tokenStream.reset();
        CharTermAttribute charTermAttribute = tokenStream.addAttribute(CharTermAttribute.class);
        List<String> token = new ArrayList<>();
        while (tokenStream.incrementToken()) {
            token.add(charTermAttribute.toString());
        }
        assertEquals(token.toString(), 6, token.size());
        assertEquals("j", token.get(0));
        assertEquals("2", token.get(1));
        assertEquals("se", token.get(2));
        assertEquals("j", token.get(3));
        assertEquals("2", token.get(4));
        assertEquals("ee", token.get(5));
    }
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) CharTermAttribute(org.apache.lucene.analysis.tokenattributes.CharTermAttribute) IndexSettings(org.elasticsearch.index.IndexSettings) ArrayList(java.util.ArrayList) Environment(org.elasticsearch.env.Environment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 69 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class AnalysisRegistryTests method testBuiltInAnalyzersAreCached.

public void testBuiltInAnalyzersAreCached() throws IOException {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings);
    IndexAnalyzers indexAnalyzers = new AnalysisRegistry(new Environment(settings), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()).build(idxSettings);
    IndexAnalyzers otherIndexAnalyzers = new AnalysisRegistry(new Environment(settings), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()).build(idxSettings);
    final int numIters = randomIntBetween(5, 20);
    for (int i = 0; i < numIters; i++) {
        PreBuiltAnalyzers preBuiltAnalyzers = RandomPicks.randomFrom(random(), PreBuiltAnalyzers.values());
        assertSame(indexAnalyzers.get(preBuiltAnalyzers.name()), otherIndexAnalyzers.get(preBuiltAnalyzers.name()));
    }
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) PreBuiltAnalyzers(org.elasticsearch.indices.analysis.PreBuiltAnalyzers) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 70 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class AnalysisRegistryTests method testNoTypeOrTokenizerErrorMessage.

public void testNoTypeOrTokenizerErrorMessage() throws IOException {
    Version version = VersionUtils.randomVersion(random());
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).putArray("index.analysis.analyzer.test_analyzer.filter", new String[] { "lowercase", "stop", "shingle" }).putArray("index.analysis.analyzer.test_analyzer.char_filter", new String[] { "html_strip" }).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new AnalysisRegistry(new Environment(settings), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()).build(idxSettings));
    assertThat(e.getMessage(), equalTo("analyzer [test_analyzer] must specify either an analyzer type, or a tokenizer"));
}
Also used : Version(org.elasticsearch.Version) IndexSettings(org.elasticsearch.index.IndexSettings) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Aggregations

Environment (org.elasticsearch.env.Environment)130 Settings (org.elasticsearch.common.settings.Settings)84 Path (java.nio.file.Path)66 Matchers.containsString (org.hamcrest.Matchers.containsString)42 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)26 TestEnvironment (org.elasticsearch.env.TestEnvironment)22 IndexSettings (org.elasticsearch.index.IndexSettings)21 UserException (org.elasticsearch.cli.UserException)17 IOException (java.io.IOException)15 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 MockTerminal (org.elasticsearch.cli.MockTerminal)8 ClusterState (org.elasticsearch.cluster.ClusterState)8 ScriptService (org.elasticsearch.script.ScriptService)8 HashMap (java.util.HashMap)7 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)7 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)7 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 ArrayList (java.util.ArrayList)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 Before (org.junit.Before)6