Search in sources :

Example 46 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class SimilarityService method addSimilarities.

private Map<String, SimilarityProvider> addSimilarities(Map<String, Settings> similaritySettings, Settings indexSettings, Map<String, TriFunction<String, Settings, Settings, SimilarityProvider>> similarities) {
    Map<String, SimilarityProvider> providers = new HashMap<>(similarities.size());
    for (Map.Entry<String, TriFunction<String, Settings, Settings, SimilarityProvider>> entry : similarities.entrySet()) {
        String name = entry.getKey();
        TriFunction<String, Settings, Settings, SimilarityProvider> factory = entry.getValue();
        Settings providerSettings = similaritySettings.get(name);
        if (providerSettings == null) {
            providerSettings = Settings.Builder.EMPTY_SETTINGS;
        }
        providers.put(name, factory.apply(name, providerSettings, indexSettings));
    }
    return providers;
}
Also used : HashMap(java.util.HashMap) TriFunction(org.elasticsearch.common.TriFunction) HashMap(java.util.HashMap) Map(java.util.Map) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 47 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class TransportAnalyzeAction method getTokenFilterFactories.

private static TokenFilterFactory[] getTokenFilterFactories(AnalyzeRequest request, IndexSettings indexSettings, AnalysisRegistry analysisRegistry, Environment environment, TokenFilterFactory[] tokenFilterFactories) throws IOException {
    if (request.tokenFilters() != null && request.tokenFilters().size() > 0) {
        tokenFilterFactories = new TokenFilterFactory[request.tokenFilters().size()];
        for (int i = 0; i < request.tokenFilters().size(); i++) {
            final AnalyzeRequest.NameOrDefinition tokenFilter = request.tokenFilters().get(i);
            // parse anonymous settings
            if (tokenFilter.definition != null) {
                Settings settings = getAnonymousSettings(tokenFilter.definition);
                String filterTypeName = settings.get("type");
                if (filterTypeName == null) {
                    throw new IllegalArgumentException("Missing [type] setting for anonymous token filter: " + tokenFilter.definition);
                }
                AnalysisModule.AnalysisProvider<TokenFilterFactory> tokenFilterFactoryFactory = analysisRegistry.getTokenFilterProvider(filterTypeName);
                if (tokenFilterFactoryFactory == null) {
                    throw new IllegalArgumentException("failed to find global token filter under [" + filterTypeName + "]");
                }
                // Need to set anonymous "name" of tokenfilter
                tokenFilterFactories[i] = tokenFilterFactoryFactory.get(getNaIndexSettings(settings), environment, "_anonymous_tokenfilter_[" + i + "]", settings);
            } else {
                AnalysisModule.AnalysisProvider<TokenFilterFactory> tokenFilterFactoryFactory;
                if (indexSettings == null) {
                    tokenFilterFactoryFactory = analysisRegistry.getTokenFilterProvider(tokenFilter.name);
                    if (tokenFilterFactoryFactory == null) {
                        throw new IllegalArgumentException("failed to find global token filter under [" + tokenFilter.name + "]");
                    }
                    tokenFilterFactories[i] = tokenFilterFactoryFactory.get(environment, tokenFilter.name);
                } else {
                    tokenFilterFactoryFactory = analysisRegistry.getTokenFilterProvider(tokenFilter.name, indexSettings);
                    if (tokenFilterFactoryFactory == null) {
                        throw new IllegalArgumentException("failed to find token filter under [" + tokenFilter.name + "]");
                    }
                    tokenFilterFactories[i] = tokenFilterFactoryFactory.get(indexSettings, environment, tokenFilter.name, AnalysisRegistry.getSettingsFromIndexSettings(indexSettings, AnalysisRegistry.INDEX_ANALYSIS_FILTER + "." + tokenFilter.name));
                }
            }
            if (tokenFilterFactories[i] == null) {
                throw new IllegalArgumentException("failed to find or create token filter under [" + tokenFilter.name + "]");
            }
        }
    }
    return tokenFilterFactories;
}
Also used : AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) TokenFilterFactory(org.elasticsearch.index.analysis.TokenFilterFactory)

Example 48 with IndexSettings

use of org.elasticsearch.index.IndexSettings 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 49 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class StopAnalyzerTests method testDefaultsCompoundAnalysis.

public void testDefaultsCompoundAnalysis() throws Exception {
    String json = "/org/elasticsearch/index/analysis/stop.json";
    Settings settings = Settings.builder().loadFromStream(json, getClass().getResourceAsStream(json)).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(idxSettings, settings).indexAnalyzers;
    NamedAnalyzer analyzer1 = indexAnalyzers.get("analyzer1");
    assertTokenStreamContents(analyzer1.tokenStream("test", "to be or not to be"), new String[0]);
    NamedAnalyzer analyzer2 = indexAnalyzers.get("analyzer2");
    assertTokenStreamContents(analyzer2.tokenStream("test", "to be or not to be"), new String[0]);
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 50 with IndexSettings

use of org.elasticsearch.index.IndexSettings 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)

Aggregations

IndexSettings (org.elasticsearch.index.IndexSettings)83 Settings (org.elasticsearch.common.settings.Settings)53 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)28 Index (org.elasticsearch.index.Index)25 ShardId (org.elasticsearch.index.shard.ShardId)13 Environment (org.elasticsearch.env.Environment)12 IOException (java.io.IOException)11 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)11 Path (java.nio.file.Path)9 ShardPath (org.elasticsearch.index.shard.ShardPath)9 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 Directory (org.apache.lucene.store.Directory)8 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)7 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 HashMap (java.util.HashMap)5 Version (org.elasticsearch.Version)5 IndexService (org.elasticsearch.index.IndexService)5 Store (org.elasticsearch.index.store.Store)5 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4