Java Code Examples for org.elasticsearch.Version#onOrAfter()
The following examples show how to use
org.elasticsearch.Version#onOrAfter() .
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: QueryParseContext.java From Elasticsearch with Apache License 2.0 | 6 votes |
private MappedFieldType failIfFieldMappingNotFound(String name, MappedFieldType fieldMapping) { if (fieldMapping != null || allowUnmappedFields) { return fieldMapping; } else if (mapUnmappedFieldAsString){ StringFieldMapper.Builder builder = MapperBuilders.stringField(name); // it would be better to pass the real index settings, but they are not easily accessible from here... Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexQueryParser.getIndexCreatedVersion()).build(); return builder.build(new Mapper.BuilderContext(settings, new ContentPath(1))).fieldType(); } else { Version indexCreatedVersion = indexQueryParser.getIndexCreatedVersion(); if (fieldMapping == null && indexCreatedVersion.onOrAfter(Version.V_1_4_0_Beta1)) { throw new QueryParsingException(this, "Strict field resolution and no field mapping can be found for the field with name [" + name + "]"); } else { return fieldMapping; } } }
Example 2
Source File: PatternAnalyzerProvider.java From Elasticsearch with Apache License 2.0 | 6 votes |
@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 3
Source File: OperationRouting.java From Elasticsearch with Apache License 2.0 | 6 votes |
@SuppressForbidden(reason = "Math#abs is trappy") private int generateShardId(ClusterState clusterState, String index, String type, String id, @Nullable String routing) { IndexMetaData indexMetaData = clusterState.metaData().index(index); if (indexMetaData == null) { throw new IndexNotFoundException(index); } final Version createdVersion = indexMetaData.getCreationVersion(); final HashFunction hashFunction = indexMetaData.getRoutingHashFunction(); final boolean useType = indexMetaData.getRoutingUseType(); final int hash; if (routing == null) { if (!useType) { hash = hash(hashFunction, id); } else { hash = hash(hashFunction, type, id); } } else { hash = hash(hashFunction, routing); } if (createdVersion.onOrAfter(Version.V_2_0_0_beta1)) { return MathUtils.mod(hash, indexMetaData.getNumberOfShards()); } else { return Math.abs(hash % indexMetaData.getNumberOfShards()); } }
Example 4
Source File: MappingMetaData.java From Elasticsearch with Apache License 2.0 | 6 votes |
public static String parseStringTimestamp(String timestampAsString, FormatDateTimeFormatter dateTimeFormatter, Version version) throws TimestampParsingException { try { // no need for unix timestamp parsing in 2.x FormatDateTimeFormatter formatter = version.onOrAfter(Version.V_2_0_0_beta1) ? dateTimeFormatter : EPOCH_MILLIS_PARSER; return Long.toString(formatter.parser().parseMillis(timestampAsString)); } catch (RuntimeException e) { if (version.before(Version.V_2_0_0_beta1)) { try { return Long.toString(dateTimeFormatter.parser().parseMillis(timestampAsString)); } catch (RuntimeException e1) { throw new TimestampParsingException(timestampAsString, e1); } } throw new TimestampParsingException(timestampAsString, e); } }
Example 5
Source File: DocumentMapperParser.java From Elasticsearch with Apache License 2.0 | 5 votes |
public static void checkNoRemainingFields(Map<String, Object> fieldNodeMap, Version indexVersionCreated, String message) { if (!fieldNodeMap.isEmpty()) { if (indexVersionCreated.onOrAfter(Version.V_2_0_0_beta1)) { throw new MapperParsingException(message + getRemainingFields(fieldNodeMap)); } else { logger.debug(message + "{}", getRemainingFields(fieldNodeMap)); } } }
Example 6
Source File: TimestampFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
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 7
Source File: HyperLogLogDistinctAggregation.java From crate with Apache License 2.0 | 5 votes |
@Nullable @Override public HllState newState(RamAccounting ramAccounting, Version indexVersionCreated, Version minNodeInCluster, MemoryManager memoryManager) { return new HllState(dataType, minNodeInCluster.onOrAfter(Version.V_4_1_0)); }
Example 8
Source File: TypeParsers.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** * Parse common field attributes such as {@code doc_values} or {@code store}. */ public static void parseField(FieldMapper.Builder builder, String name, Map<String, Object> fieldNode, Mapper.TypeParser.ParserContext parserContext) { Version indexVersionCreated = parserContext.indexVersionCreated(); for (Iterator<Map.Entry<String, Object>> iterator = fieldNode.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); final String propName = Strings.toUnderscoreCase(entry.getKey()); final Object propNode = entry.getValue(); if (propName.equals("index_name") && indexVersionCreated.before(Version.V_2_0_0_beta1)) { builder.indexName(propNode.toString()); iterator.remove(); } else if (propName.equals("store")) { builder.store(parseStore(name, propNode.toString())); iterator.remove(); } else if (propName.equals("index")) { parseIndex(name, propNode.toString(), builder); iterator.remove(); } else if (propName.equals(DOC_VALUES)) { builder.docValues(nodeBooleanValue(propNode)); iterator.remove(); } else if (propName.equals("boost")) { builder.boost(nodeFloatValue(propNode)); iterator.remove(); } else if (propName.equals("omit_norms")) { builder.omitNorms(nodeBooleanValue(propNode)); iterator.remove(); } else if (propName.equals("norms")) { final Map<String, Object> properties = nodeMapValue(propNode, "norms"); for (Iterator<Entry<String, Object>> propsIterator = properties.entrySet().iterator(); propsIterator.hasNext();) { Entry<String, Object> entry2 = propsIterator.next(); final String propName2 = Strings.toUnderscoreCase(entry2.getKey()); final Object propNode2 = entry2.getValue(); if (propName2.equals("enabled")) { builder.omitNorms(!nodeBooleanValue(propNode2)); propsIterator.remove(); } else if (propName2.equals(Loading.KEY)) { builder.normsLoading(Loading.parse(nodeStringValue(propNode2, null), null)); propsIterator.remove(); } } DocumentMapperParser.checkNoRemainingFields(propName, properties, parserContext.indexVersionCreated()); iterator.remove(); } else if (propName.equals("omit_term_freq_and_positions")) { final IndexOptions op = nodeBooleanValue(propNode) ? IndexOptions.DOCS : IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; if (indexVersionCreated.onOrAfter(Version.V_1_0_0_RC2)) { throw new ElasticsearchParseException("'omit_term_freq_and_positions' is not supported anymore - use ['index_options' : 'docs'] instead"); } // deprecated option for BW compat builder.indexOptions(op); iterator.remove(); } else if (propName.equals("index_options")) { builder.indexOptions(nodeIndexOptionValue(propNode)); iterator.remove(); } else if (propName.equals("include_in_all")) { builder.includeInAll(nodeBooleanValue(propNode)); iterator.remove(); } else if (propName.equals("postings_format") && indexVersionCreated.before(Version.V_2_0_0_beta1)) { // ignore for old indexes iterator.remove(); } else if (propName.equals("doc_values_format") && indexVersionCreated.before(Version.V_2_0_0_beta1)) { // ignore for old indexes iterator.remove(); } else if (propName.equals("similarity")) { builder.similarity(parserContext.similarityLookupService().similarity(propNode.toString())); iterator.remove(); } else if (propName.equals("fielddata")) { final Settings settings = Settings.builder().put(SettingsLoader.Helper.loadNestedFromMap(nodeMapValue(propNode, "fielddata"))).build(); builder.fieldDataSettings(settings); iterator.remove(); } else if (propName.equals("copy_to")) { if (parserContext.isWithinMultiField()) { if (indexVersionCreated.after(Version.V_2_1_0) || (indexVersionCreated.after(Version.V_2_0_1) && indexVersionCreated.before(Version.V_2_1_0))) { throw new MapperParsingException("copy_to in multi fields is not allowed. Found the copy_to in field [" + name + "] which is within a multi field."); } else { ESLoggerFactory.getLogger("mapping [" + parserContext.type() + "]").warn("Found a copy_to in field [" + name + "] which is within a multi field. This feature has been removed and the copy_to will be ignored."); // we still parse this, otherwise the message will only appear once and the copy_to removed. After that it will appear again. Better to have it always. } } parseCopyFields(propNode, builder); iterator.remove(); } } if (indexVersionCreated.before(Version.V_2_2_0)) { // analyzer, search_analyzer, term_vectors were accepted on all fields // before 2.2, even though it made little sense parseAnalyzersAndTermVectors(builder, name, fieldNode, parserContext); } }
Example 9
Source File: NamedDiffableValueSerializer.java From crate with Apache License 2.0 | 4 votes |
@Override public boolean supportsVersion(Diff<T> value, Version version) { return version.onOrAfter(((NamedDiff<?>)value).getMinimalSupportedVersion()); }
Example 10
Source File: NamedDiffableValueSerializer.java From crate with Apache License 2.0 | 4 votes |
@Override public boolean supportsVersion(T value, Version version) { return version.onOrAfter(value.getMinimalSupportedVersion()); }