Java Code Examples for org.elasticsearch.Version#indexCreated()

The following examples show how to use org.elasticsearch.Version#indexCreated() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexSettings.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the settings and index metadata and notifies all registered settings consumers with the new settings iff at least one setting has changed.
 *
 * @return <code>true</code> iff any setting has been updated otherwise <code>false</code>.
 */
public synchronized boolean updateIndexMetaData(IndexMetaData indexMetaData) {
    final Settings newSettings = indexMetaData.getSettings();
    if (version.equals(Version.indexCreated(newSettings)) == false) {
        throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + Version.indexCreated(newSettings));
    }
    final String newUUID = newSettings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE);
    if (newUUID.equals(getUUID()) == false) {
        throw new IllegalArgumentException("uuid mismatch on settings update expected: " + getUUID() + " but was: " + newUUID);
    }
    this.indexMetaData = indexMetaData;
    final Settings newIndexSettings = Settings.builder().put(nodeSettings).put(newSettings).build();
    if (same(this.settings, newIndexSettings)) {
        // nothing to update, same settings
        return false;
    }
    scopedSettings.applySettings(newSettings);
    this.settings = newIndexSettings;
    return true;
}
 
Example 2
Source File: StandardAnalyzerProvider.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public StandardAnalyzerProvider(Index index, Settings indexSettings, Environment env, String name, Settings settings) {
    super(index, indexSettings, name, settings);
    this.esVersion = Version.indexCreated(indexSettings);
    final CharArraySet defaultStopwords;
    if (esVersion.onOrAfter(Version.V_1_0_0_Beta1)) {
        defaultStopwords = CharArraySet.EMPTY_SET;
    } else {
        defaultStopwords = StopAnalyzer.ENGLISH_STOP_WORDS_SET;
    }

    CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);
    int maxTokenLength = settings.getAsInt("max_token_length", StandardAnalyzer.DEFAULT_MAX_TOKEN_LENGTH);
    standardAnalyzer = new StandardAnalyzer(stopWords);
    standardAnalyzer.setVersion(version);
    standardAnalyzer.setMaxTokenLength(maxTokenLength);
}
 
Example 3
Source File: PatternAnalyzerProvider.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public PatternAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, Environment env, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);

    Version esVersion = Version.indexCreated(indexSettingsService.getSettings());
    final CharArraySet defaultStopwords;
    if (esVersion.onOrAfter(Version.V_1_0_0_RC1)) {
        defaultStopwords = CharArraySet.EMPTY_SET;
    } else {
        defaultStopwords = StopAnalyzer.ENGLISH_STOP_WORDS_SET;
    }
    boolean lowercase = settings.getAsBoolean("lowercase", true);
    CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);

    String sPattern = settings.get("pattern", "\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/);
    if (sPattern == null) {
        throw new IllegalArgumentException("Analyzer [" + name + "] of type pattern must have a `pattern` set");
    }
    Pattern pattern = Regex.compile(sPattern, settings.get("flags"));

    analyzer = new PatternAnalyzer(pattern, lowercase, stopWords);
}
 
Example 4
Source File: PreBuiltTokenFilterFactoryFactory.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public TokenFilterFactory create(String name, Settings settings) {
    Version indexVersion = Version.indexCreated(settings);
    if (!Version.CURRENT.equals(indexVersion)) {
        PreBuiltTokenFilters preBuiltTokenFilters = PreBuiltTokenFilters.getOrDefault(name, null);
        if (preBuiltTokenFilters != null) {
            return preBuiltTokenFilters.getTokenFilterFactory(indexVersion);
        }
    }
    return tokenFilterFactory;
}
 
Example 5
Source File: PreConfiguredAnalysisComponent.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public T get(IndexSettings indexSettings, Environment environment, String name, Settings settings) throws IOException {
    Version versionCreated = Version.indexCreated(settings);
    synchronized (this) {
        T factory = cache.get(versionCreated);
        if (factory == null) {
            factory = create(versionCreated);
            cache.put(versionCreated, factory);
        }
        return factory;
    }
}
 
Example 6
Source File: PreBuiltAnalyzerProviderFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public AnalyzerProvider<?> get(IndexSettings indexSettings,
                               Environment environment,
                               String name,
                               Settings settings) throws IOException {
    Version versionCreated = Version.indexCreated(settings);
    if (Version.CURRENT.equals(versionCreated) == false) {
        return super.get(indexSettings, environment, name, settings);
    } else {
        return current;
    }
}
 
Example 7
Source File: IndexRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Version getVersion(MetaData metaData, String concreteIndex) {
    // this can go away in 3.0 but is here now for easy backporting - since in 2.x we need the version on the timestamp stuff
    final IndexMetaData indexMetaData = metaData.getIndices().get(concreteIndex);
    if (indexMetaData == null) {
        throw new IndexNotFoundException(concreteIndex);
    }
    return Version.indexCreated(indexMetaData.getSettings());
}
 
Example 8
Source File: Mapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Nullable
public Version indexCreatedVersion() {
    if (indexSettings == null) {
        return null;
    }
    return Version.indexCreated(indexSettings);
}
 
Example 9
Source File: TimestampFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static FormatDateTimeFormatter getDateTimeFormatter(Settings indexSettings) {
    Version indexCreated = Version.indexCreated(indexSettings);
    if (indexCreated.onOrAfter(Version.V_2_0_0_beta1)) {
        return Defaults.DATE_TIME_FORMATTER;
    } else {
        return Defaults.DATE_TIME_FORMATTER_BEFORE_2_0;
    }
}
 
Example 10
Source File: ParentFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static MappedFieldType joinFieldTypeForParentType(String parentType, Settings indexSettings) {
    MappedFieldType parentJoinFieldType = Defaults.JOIN_FIELD_TYPE.clone();
    parentJoinFieldType.setNames(new MappedFieldType.Names(joinField(parentType)));

    Version indexCreated = Version.indexCreated(indexSettings);
    if (indexCreated.before(Version.V_2_0_0_beta1)) {
        parentJoinFieldType.setHasDocValues(false);
        parentJoinFieldType.setDocValuesType(DocValuesType.NONE);
    }
    parentJoinFieldType.freeze();
    return parentJoinFieldType;
}
 
Example 11
Source File: DocumentMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public DocumentMapper build(MapperService mapperService) {
    Objects.requireNonNull(rootObjectMapper, "Mapper builder must have the root object mapper set");
    Mapping mapping = new Mapping(
            Version.indexCreated(mapperService.indexSettings()),
            rootObjectMapper,
            metadataMappers.values().toArray(new MetadataFieldMapper[metadataMappers.values().size()]),
            sourceTransforms.toArray(new SourceTransform[sourceTransforms.size()]),
            meta);
    return new DocumentMapper(mapperService, mapping);
}
 
Example 12
Source File: DocumentMapperParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public DocumentMapperParser(Settings indexSettings, MapperService mapperService, AnalysisService analysisService,
                            SimilarityLookupService similarityLookupService, ScriptService scriptService,
                            MapperRegistry mapperRegistry,
                            @Nullable DynamicArrayFieldMapperBuilderFactory dynamicArrayFieldMapperBuilderFactory) {
    this.dynamicArrayFieldMapperBuilderFactory = dynamicArrayFieldMapperBuilderFactory;
    this.parseFieldMatcher = new ParseFieldMatcher(indexSettings);
    this.scriptService = scriptService;
    this.mapperService = mapperService;
    this.analysisService = analysisService;
    this.similarityLookupService = similarityLookupService;
    this.typeParsers = mapperRegistry.getMapperParsers();
    this.rootTypeParsers = mapperRegistry.getMetadataMapperParsers();
    indexVersionCreated = Version.indexCreated(indexSettings);
}
 
Example 13
Source File: PreBuiltCharFilterFactoryFactory.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public CharFilterFactory create(String name, Settings settings) {
    Version indexVersion = Version.indexCreated(settings);
    if (!Version.CURRENT.equals(indexVersion)) {
        PreBuiltCharFilters preBuiltCharFilters = PreBuiltCharFilters.getOrDefault(name, null);
        if (preBuiltCharFilters != null) {
            return preBuiltCharFilters.getCharFilterFactory(indexVersion);
        }
    }

    return charFilterFactory;
}
 
Example 14
Source File: PreBuiltAnalyzerProviderFactory.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AnalyzerProvider create(String name, Settings settings) {
    Version indexVersion = Version.indexCreated(settings);
    if (!Version.CURRENT.equals(indexVersion)) {
        PreBuiltAnalyzers preBuiltAnalyzers = PreBuiltAnalyzers.getOrDefault(name, null);
        if (preBuiltAnalyzers != null) {
            Analyzer analyzer = preBuiltAnalyzers.getAnalyzer(indexVersion);
            return new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, analyzer);
        }
    }

    return analyzerProvider;
}
 
Example 15
Source File: PreBuiltTokenizerFactoryFactory.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public TokenizerFactory create(String name, Settings settings) {
    Version indexVersion = Version.indexCreated(settings);
    if (!Version.CURRENT.equals(indexVersion)) {
        PreBuiltTokenizers preBuiltTokenizers = PreBuiltTokenizers.getOrDefault(name, null);
        if (preBuiltTokenizers != null) {
            return preBuiltTokenizers.getTokenizerFactory(indexVersion);
        }
    }

    return tokenizerFactory;
}
 
Example 16
Source File: StandardHtmlStripAnalyzerProvider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public StandardHtmlStripAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, Environment env,  @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);
    this.esVersion = Version.indexCreated(indexSettingsService.getSettings());
    final CharArraySet defaultStopwords;
    if (esVersion.onOrAfter(Version.V_1_0_0_RC1)) {
        defaultStopwords = CharArraySet.EMPTY_SET;
    } else {
        defaultStopwords = StopAnalyzer.ENGLISH_STOP_WORDS_SET;
    }
    CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);
    analyzer = new StandardHtmlStripAnalyzer(stopWords);
    analyzer.setVersion(version);
}
 
Example 17
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public org.apache.lucene.util.Version minimumCompatibleVersion() {
    org.apache.lucene.util.Version luceneVersion = null;
    for (Segment segment : engine().segments(false)) {
        if (luceneVersion == null || luceneVersion.onOrAfter(segment.getVersion())) {
            luceneVersion = segment.getVersion();
        }
    }
    return luceneVersion == null ? Version.indexCreated(indexSettings).luceneVersion : luceneVersion;
}
 
Example 18
Source File: Mapper.java    From crate with Apache License 2.0 4 votes vote down vote up
public Version indexCreatedVersion() {
    return Version.indexCreated(indexSettings);
}
 
Example 19
Source File: QueryParseContext.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public QueryParseContext(Index index, IndexQueryParserService indexQueryParser) {
    this.index = index;
    this.indexVersionCreated = Version.indexCreated(indexQueryParser.indexSettings());
    this.indexQueryParser = indexQueryParser;
}
 
Example 20
Source File: IndexQueryParserService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * @return The lowest node version in the cluster when the index was created or <code>null</code> if that was unknown
 */
public Version getIndexCreatedVersion() {
    return Version.indexCreated(indexSettingsService.getSettings());
}