Search in sources :

Example 56 with IndexSettings

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

the class PatternCaptureTokenFilterTests method testPatternCaptureTokenFilter.

public void testPatternCaptureTokenFilter() throws Exception {
    String json = "/org/elasticsearch/index/analysis/pattern_capture.json";
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).loadFromStream(json, getClass().getResourceAsStream(json)).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(idxSettings, settings).indexAnalyzers;
    NamedAnalyzer analyzer1 = indexAnalyzers.get("single");
    assertTokenStreamContents(analyzer1.tokenStream("test", "foobarbaz"), new String[] { "foobarbaz", "foobar", "foo" });
    NamedAnalyzer analyzer2 = indexAnalyzers.get("multi");
    assertTokenStreamContents(analyzer2.tokenStream("test", "abc123def"), new String[] { "abc123def", "abc", "123", "def" });
    NamedAnalyzer analyzer3 = indexAnalyzers.get("preserve");
    assertTokenStreamContents(analyzer3.tokenStream("test", "foobarbaz"), new String[] { "foobar", "foo" });
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 57 with IndexSettings

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

the class CharFilterTests method testHtmlStripCharFilter.

public void testHtmlStripCharFilter() throws Exception {
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.analysis.analyzer.custom_with_char_filter.tokenizer", "standard").putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "html_strip").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", "<b>hello</b>!"), new String[] { "hello" });
    // Repeat one more time to make sure that char filter is reinitialized correctly
    assertTokenStreamContents(analyzer1.tokenStream("test", "<b>hello</b>!"), new String[] { "hello" });
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 58 with IndexSettings

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

the class FlattenGraphTokenFilterFactoryTests method testBasic.

public void testBasic() throws IOException {
    Index index = new Index("test", "_na_");
    String name = "ngr";
    Settings indexSettings = newAnalysisSettingsBuilder().build();
    IndexSettings indexProperties = IndexSettingsModule.newIndexSettings(index, indexSettings);
    Settings settings = newAnalysisSettingsBuilder().build();
    // "wow that's funny" and "what the fudge" are separate side paths, in parallel with "wtf", on input:
    TokenStream in = new CannedTokenStream(0, 12, new Token[] { token("wtf", 1, 5, 0, 3), token("what", 0, 1, 0, 3), token("wow", 0, 3, 0, 3), token("the", 1, 1, 0, 3), token("fudge", 1, 3, 0, 3), token("that's", 1, 1, 0, 3), token("funny", 1, 1, 0, 3), token("happened", 1, 1, 4, 12) });
    TokenStream tokens = new FlattenGraphTokenFilterFactory(indexProperties, null, name, settings).create(in);
    // ... but on output, it's flattened to wtf/what/wow that's/the fudge/funny happened:
    assertTokenStreamContents(tokens, new String[] { "wtf", "what", "wow", "the", "that's", "fudge", "funny", "happened" }, new int[] { 0, 0, 0, 0, 0, 0, 0, 4 }, new int[] { 3, 3, 3, 3, 3, 3, 3, 12 }, new int[] { 1, 0, 0, 1, 0, 1, 0, 1 }, new int[] { 3, 1, 1, 1, 1, 1, 1, 1 }, 12);
}
Also used : CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream) TokenStream(org.apache.lucene.analysis.TokenStream) IndexSettings(org.elasticsearch.index.IndexSettings) Index(org.elasticsearch.index.Index) CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 59 with IndexSettings

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

the class AbstractSortTestCase method createMockShardContext.

protected QueryShardContext createMockShardContext() {
    Index index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    IndicesFieldDataCache cache = new IndicesFieldDataCache(Settings.EMPTY, null);
    IndexFieldDataService ifds = new IndexFieldDataService(IndexSettingsModule.newIndexSettings("test", Settings.EMPTY), cache, null, null);
    BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(idxSettings, new BitsetFilterCache.Listener() {

        @Override
        public void onRemoval(ShardId shardId, Accountable accountable) {
        }

        @Override
        public void onCache(ShardId shardId, Accountable accountable) {
        }
    });
    long nowInMillis = randomNonNegativeLong();
    return new QueryShardContext(0, idxSettings, bitsetFilterCache, ifds, null, null, scriptService, xContentRegistry(), null, null, () -> nowInMillis) {

        @Override
        public MappedFieldType fieldMapper(String name) {
            return provideMappedFieldType(name);
        }

        @Override
        public ObjectMapper getObjectMapper(String name) {
            BuilderContext context = new BuilderContext(this.getIndexSettings().getSettings(), new ContentPath());
            return new ObjectMapper.Builder<>(name).nested(Nested.newNested(false, false)).build(context);
        }
    };
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) Accountable(org.apache.lucene.util.Accountable) Index(org.elasticsearch.index.Index) ContentPath(org.elasticsearch.index.mapper.ContentPath) ShardId(org.elasticsearch.index.shard.ShardId) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) BuilderContext(org.elasticsearch.index.mapper.Mapper.BuilderContext) BitsetFilterCache(org.elasticsearch.index.cache.bitset.BitsetFilterCache)

Example 60 with IndexSettings

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

the class ShardSearchTransportRequestTests method testSerialize50Request.

// BWC test for changes from #20916
public void testSerialize50Request() throws IOException {
    BytesArray requestBytes = new BytesArray(Base64.getDecoder().decode("AAh4cXptdEhJcgdnT0d1ZldWyfL/sgQBJAHkDAMBAAIBAQ4TWlljWlZ5TkVmRU5xQnFQVHBjVBRZbUpod2pRV2dDSXVxRXpRaEdGVBRFZWFJY0plT2hn" + "UEpISFhmSXR6Qw5XZ1hQcmFidWhWalFSQghuUWNwZ2JjQxBtZldRREJPaGF3UnlQSE56EVhQSUtRa25Iekh3bU5kbGVECWlFT2NIeEh3RgZIYXpMTWgUeGJq" + "VU9Tdkdua3RORU5QZkNrb1EOalRyWGh5WXhvZ3plV2UUcWlXZFl2eUFUSXdPVGdMUUtYTHAJU3RKR3JxQkVJEkdEQ01xUHpnWWNaT3N3U3prSRIUeURlVFpM" + "Q1lBZERZcWpDb3NOVWIST1NyQlZtdUNrd0F1UXRvdVRjEGp6RlVMd1dqc3VtUVNaTk0JT3N2cnpLQ3ZLBmRpS1J6cgdYbmVhZnBxBUlTUU9pEEJMcm1ERXVs" + "eXhESlBoVkgTaWdUUmtVZGh4d0FFc2ZKRm9ZahNrb01XTnFFd2NWSVVDU3pWS2xBC3JVTWV3V2tUUWJUE3VGQU1Hd21CYUFMTmNQZkxobXUIZ3dxWHBxWXcF" + "bmNDZUEOTFBSTEpYZVF6Z3d2eE0PV1BucUFacll6WWRxa1hCDGxkbXNMaVRzcUZXbAtSY0NsY3FNdlJQcv8BAP////8PAQAAARQAAQp5THlIcHdQeGtMAAAB" + "AQAAAAEDbkVLAQMBCgACAAADAQABAAAAAQhIc25wRGxQbwEBQgABAAACAQMAAAEIAAAJMF9OSG9kSmh2HwABAwljRW5MVWxFbVQFemlxWG8KcXZQTkRUUGJk" + "bgECCkpMbXVMT1dtVnkISEdUUHhsd0cBAAEJAAABA2lkcz+rKsUAAAAAAAAAAAECAQYAAgwxX0ZlRWxSQkhzQ07/////DwABAAEDCnRyYXFHR1hjVHkKTERY" + "aE1HRWVySghuSWtzbEtXUwABCgEHSlRwQnhwdwAAAQECAgAAAAAAAQcyX3FlYmNDGQEEBklxZU9iUQdTc01Gek5YCWlMd2xuamNRQwNiVncAAUHt61kAAQR0" + "ZXJtP4AAAAANbUtDSnpHU3lidm5KUBUMaVpqeG9vcm5QSFlvAAEBLGdtcWxuRWpWTXdvTlhMSHh0RWlFdHBnbEF1cUNmVmhoUVlwRFZxVllnWWV1A2ZvbwEA" + "AQhwYWlubGVzc/8AALk4AAAAAAABAAAAAAAAAwpKU09PU0ZmWnhFClVqTGxMa2p3V2gKdUJwZ3R3dXFER5Hg97uT7MOmPgEADw"));
    try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
        in.setVersion(Version.V_5_0_0);
        ShardSearchTransportRequest readRequest = new ShardSearchTransportRequest();
        readRequest.readFrom(in);
        assertEquals(0, in.available());
        IllegalStateException illegalStateException = expectThrows(IllegalStateException.class, () -> readRequest.filteringAliases());
        assertEquals("alias filter for aliases: [JSOOSFfZxE, UjLlLkjwWh, uBpgtwuqDG] must be rewritten first", illegalStateException.getMessage());
        IndexMetaData.Builder indexMetadata = new IndexMetaData.Builder(baseMetaData).putAlias(AliasMetaData.newAliasMetaDataBuilder("JSOOSFfZxE").filter("{\"term\" : {\"foo\" : \"bar\"}}")).putAlias(AliasMetaData.newAliasMetaDataBuilder("UjLlLkjwWh").filter("{\"term\" : {\"foo\" : \"bar1\"}}")).putAlias(AliasMetaData.newAliasMetaDataBuilder("uBpgtwuqDG").filter("{\"term\" : {\"foo\" : \"bar2\"}}"));
        IndexSettings indexSettings = new IndexSettings(indexMetadata.build(), Settings.EMPTY);
        final long nowInMillis = randomNonNegativeLong();
        QueryShardContext context = new QueryShardContext(0, indexSettings, null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
        readRequest.rewrite(context);
        QueryBuilder queryBuilder = readRequest.filteringAliases();
        assertEquals(queryBuilder, QueryBuilders.boolQuery().should(QueryBuilders.termQuery("foo", "bar")).should(QueryBuilders.termQuery("foo", "bar1")).should(QueryBuilders.termQuery("foo", "bar2")));
        BytesStreamOutput output = new BytesStreamOutput();
        output.setVersion(Version.V_5_0_0);
        readRequest.writeTo(output);
        assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
    }
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) IndexSettings(org.elasticsearch.index.IndexSettings) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) RandomQueryBuilder(org.elasticsearch.index.query.RandomQueryBuilder) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

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