Search in sources :

Example 86 with Index

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

the class GatewayMetaStateTests method assertState.

public void assertState(ClusterChangedEvent event, boolean stateInMemory, boolean expectMetaData) throws Exception {
    MetaData inMemoryMetaData = null;
    Set<Index> oldIndicesList = emptySet();
    if (stateInMemory) {
        inMemoryMetaData = event.previousState().metaData();
        oldIndicesList = GatewayMetaState.getRelevantIndices(event.previousState(), event.previousState(), oldIndicesList);
    }
    Set<Index> newIndicesList = GatewayMetaState.getRelevantIndices(event.state(), event.previousState(), oldIndicesList);
    // third, get the actual write info
    Iterator<GatewayMetaState.IndexMetaWriteInfo> indices = GatewayMetaState.resolveStatesToBeWritten(oldIndicesList, newIndicesList, inMemoryMetaData, event.state().metaData()).iterator();
    if (expectMetaData) {
        assertThat(indices.hasNext(), equalTo(true));
        assertThat(indices.next().getNewMetaData().getIndex().getName(), equalTo("test"));
        assertThat(indices.hasNext(), equalTo(false));
    } else {
        assertThat(indices.hasNext(), equalTo(false));
    }
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Index(org.elasticsearch.index.Index)

Example 87 with Index

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

the class NGramTokenizerFactoryTests method testBackwardsCompatibilityEdgeNgramTokenFilter.

public void testBackwardsCompatibilityEdgeNgramTokenFilter() throws Exception {
    int iters = scaledRandomIntBetween(20, 100);
    for (int i = 0; i < iters; i++) {
        final Index index = new Index("test", "_na_");
        final String name = "ngr";
        Version v = randomVersion(random());
        Builder builder = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3);
        boolean reverse = random().nextBoolean();
        if (reverse) {
            builder.put("side", "back");
        }
        Settings settings = builder.build();
        Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build();
        Tokenizer tokenizer = new MockTokenizer();
        tokenizer.setReader(new StringReader("foo bar"));
        TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create(tokenizer);
        if (reverse) {
            assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class));
        } else {
            assertThat(edgeNGramTokenFilter, instanceOf(EdgeNGramTokenFilter.class));
        }
    }
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) EdgeNGramTokenFilter(org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter) Builder(org.elasticsearch.common.settings.Settings.Builder) Index(org.elasticsearch.index.Index) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) Version(org.elasticsearch.Version) StringReader(java.io.StringReader) ReverseStringFilter(org.apache.lucene.analysis.reverse.ReverseStringFilter) Tokenizer(org.apache.lucene.analysis.Tokenizer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 88 with Index

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

the class NGramTokenizerFactoryTests method testNoTokenChars.

public void testNoTokenChars() throws IOException {
    final Index index = new Index("test", "_na_");
    final String name = "ngr";
    final Settings indexSettings = newAnalysisSettingsBuilder().build();
    final Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 4).putArray("token_chars", new String[0]).build();
    Tokenizer tokenizer = new NGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create();
    tokenizer.setReader(new StringReader("1.34"));
    assertTokenStreamContents(tokenizer, new String[] { "1.", "1.3", "1.34", ".3", ".34", "34" });
}
Also used : StringReader(java.io.StringReader) Index(org.elasticsearch.index.Index) Tokenizer(org.apache.lucene.analysis.Tokenizer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 89 with Index

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

the class NGramTokenizerFactoryTests method testPreTokenizationEdge.

public void testPreTokenizationEdge() throws IOException {
    // Make sure that pretokenization works well and that it can be used even with token chars which are supplementary characters
    final Index index = new Index("test", "_na_");
    final String name = "ngr";
    final Settings indexSettings = newAnalysisSettingsBuilder().build();
    Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit").build();
    Tokenizer tokenizer = new EdgeNGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create();
    tokenizer.setReader(new StringReader("Åbc déf g𐐀f "));
    assertTokenStreamContents(tokenizer, new String[] { "Åb", "Åbc", "dé", "déf", "g𐐀", "g𐐀f" });
    settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit,punctuation,whitespace,symbol").build();
    tokenizer = new EdgeNGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create();
    tokenizer.setReader(new StringReader(" a!$ 9"));
    assertTokenStreamContents(tokenizer, new String[] { " a", " a!" });
}
Also used : StringReader(java.io.StringReader) Index(org.elasticsearch.index.Index) Tokenizer(org.apache.lucene.analysis.Tokenizer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 90 with Index

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

the class NGramTokenizerFactoryTests method testPreTokenization.

public void testPreTokenization() throws IOException {
    // Make sure that pretokenization works well and that it can be used even with token chars which are supplementary characters
    final Index index = new Index("test", "_na_");
    final String name = "ngr";
    final Settings indexSettings = newAnalysisSettingsBuilder().build();
    Settings settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit").build();
    Tokenizer tokenizer = new NGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create();
    tokenizer.setReader(new StringReader("Åbc déf g𐐀f "));
    assertTokenStreamContents(tokenizer, new String[] { "Åb", "Åbc", "bc", "dé", "déf", "éf", "g𐐀", "g𐐀f", "𐐀f" });
    settings = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit,punctuation,whitespace,symbol").build();
    tokenizer = new NGramTokenizerFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create();
    tokenizer.setReader(new StringReader(" a!$ 9"));
    assertTokenStreamContents(tokenizer, new String[] { " a", " a!", "a!", "a!$", "!$", "!$ ", "$ ", "$ 9", " 9" });
}
Also used : StringReader(java.io.StringReader) Index(org.elasticsearch.index.Index) Tokenizer(org.apache.lucene.analysis.Tokenizer) MockTokenizer(org.apache.lucene.analysis.MockTokenizer) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Aggregations

Index (org.elasticsearch.index.Index)366 ShardId (org.elasticsearch.index.shard.ShardId)108 Settings (org.elasticsearch.common.settings.Settings)95 ClusterState (org.elasticsearch.cluster.ClusterState)88 ArrayList (java.util.ArrayList)79 IOException (java.io.IOException)74 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)65 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)65 HashMap (java.util.HashMap)61 Map (java.util.Map)61 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)59 List (java.util.List)56 HashSet (java.util.HashSet)50 Path (java.nio.file.Path)45 IndexSettings (org.elasticsearch.index.IndexSettings)44 IndexService (org.elasticsearch.index.IndexService)43 Set (java.util.Set)40 Metadata (org.elasticsearch.cluster.metadata.Metadata)39 ClusterService (org.elasticsearch.cluster.service.ClusterService)39 ActionListener (org.elasticsearch.action.ActionListener)35