Search in sources :

Example 16 with IndexSettings

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

the class CharFilterTests method testMappingCharFilter.

public void testMappingCharFilter() throws Exception {
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.analysis.char_filter.my_mapping.type", "mapping").putArray("index.analysis.char_filter.my_mapping.mappings", "ph=>f", "qu=>q").put("index.analysis.analyzer.custom_with_char_filter.tokenizer", "standard").putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "my_mapping").put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(idxSettings, settings).indexAnalyzers;
    NamedAnalyzer analyzer1 = indexAnalyzers.get("custom_with_char_filter");
    assertTokenStreamContents(analyzer1.tokenStream("test", "jeff quit phish"), new String[] { "jeff", "qit", "fish" });
    // Repeat one more time to make sure that char filter is reinitialized correctly
    assertTokenStreamContents(analyzer1.tokenStream("test", "jeff quit phish"), new String[] { "jeff", "qit", "fish" });
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 17 with IndexSettings

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

the class CompoundAnalysisTests method testDefaultsCompoundAnalysis.

public void testDefaultsCompoundAnalysis() throws Exception {
    Settings settings = getJsonSettings();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    AnalysisModule analysisModule = new AnalysisModule(new Environment(settings), singletonList(new AnalysisPlugin() {

        @Override
        public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
            return singletonMap("myfilter", MyFilterTokenFilterFactory::new);
        }
    }));
    TokenFilterFactory filterFactory = analysisModule.getAnalysisRegistry().buildTokenFilterFactories(idxSettings).get("dict_dec");
    MatcherAssert.assertThat(filterFactory, instanceOf(DictionaryCompoundWordTokenFilterFactory.class));
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Environment(org.elasticsearch.env.Environment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule) MyFilterTokenFilterFactory(org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory) AnalysisProvider(org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) MyFilterTokenFilterFactory(org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory) DictionaryCompoundWordTokenFilterFactory(org.elasticsearch.index.analysis.compound.DictionaryCompoundWordTokenFilterFactory) DictionaryCompoundWordTokenFilterFactory(org.elasticsearch.index.analysis.compound.DictionaryCompoundWordTokenFilterFactory) AnalysisPlugin(org.elasticsearch.plugins.AnalysisPlugin)

Example 18 with IndexSettings

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

the class CompoundAnalysisTests method analyze.

private List<String> analyze(Settings settings, String analyzerName, String text) throws IOException {
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    AnalysisModule analysisModule = new AnalysisModule(new Environment(settings), singletonList(new AnalysisPlugin() {

        @Override
        public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
            return singletonMap("myfilter", MyFilterTokenFilterFactory::new);
        }
    }));
    IndexAnalyzers indexAnalyzers = analysisModule.getAnalysisRegistry().build(idxSettings);
    Analyzer analyzer = indexAnalyzers.get(analyzerName).analyzer();
    AllEntries allEntries = new AllEntries();
    allEntries.addText("field1", text, 1.0f);
    TokenStream stream = AllTokenStream.allTokenStream("_all", text, 1.0f, analyzer);
    stream.reset();
    CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class);
    List<String> terms = new ArrayList<>();
    while (stream.incrementToken()) {
        String tokText = termAtt.toString();
        terms.add(tokText);
    }
    return terms;
}
Also used : AllTokenStream(org.elasticsearch.common.lucene.all.AllTokenStream) TokenStream(org.apache.lucene.analysis.TokenStream) IndexSettings(org.elasticsearch.index.IndexSettings) ArrayList(java.util.ArrayList) Analyzer(org.apache.lucene.analysis.Analyzer) AllEntries(org.elasticsearch.common.lucene.all.AllEntries) CharTermAttribute(org.apache.lucene.analysis.tokenattributes.CharTermAttribute) Environment(org.elasticsearch.env.Environment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule) MyFilterTokenFilterFactory(org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory) AnalysisProvider(org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider) AnalysisPlugin(org.elasticsearch.plugins.AnalysisPlugin)

Example 19 with IndexSettings

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

the class AnalysisRegistryTests method testDefaultAnalyzers.

public void testDefaultAnalyzers() 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()).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    IndexAnalyzers indexAnalyzers = new AnalysisRegistry(new Environment(settings), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()).build(idxSettings);
    assertThat(indexAnalyzers.getDefaultIndexAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class));
    assertThat(indexAnalyzers.getDefaultSearchQuoteAnalyzer().analyzer(), instanceOf(StandardAnalyzer.class));
}
Also used : Version(org.elasticsearch.Version) IndexSettings(org.elasticsearch.index.IndexSettings) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 20 with IndexSettings

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

the class DateFieldTypeTests method testTermQuery.

public void testTermQuery() {
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
    QueryShardContext context = new QueryShardContext(0, new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings), null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    String date = "2015-10-12T14:10:55";
    long instant = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime(date).getMillis();
    ft.setIndexOptions(IndexOptions.DOCS);
    Query expected = new IndexOrDocValuesQuery(LongPoint.newRangeQuery("field", instant, instant + 999), SortedNumericDocValuesField.newRangeQuery("field", instant, instant + 999));
    assertEquals(expected, ft.termQuery(date, context));
    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ft.termQuery(date, context));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
Also used : Query(org.apache.lucene.search.Query) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery) IndexSettings(org.elasticsearch.index.IndexSettings) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery) 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