Java Code Examples for org.elasticsearch.Version#before()
The following examples show how to use
org.elasticsearch.Version#before() .
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: Mapping.java From Elasticsearch with Apache License 2.0 | 6 votes |
public Mapping(Version indexCreated, RootObjectMapper rootObjectMapper, MetadataFieldMapper[] metadataMappers, SourceTransform[] sourceTransforms, ImmutableMap<String, Object> meta) { this.indexCreated = indexCreated; this.metadataMappers = metadataMappers; ImmutableMap.Builder<Class<? extends MetadataFieldMapper>, MetadataFieldMapper> builder = ImmutableMap.builder(); for (MetadataFieldMapper metadataMapper : metadataMappers) { if (indexCreated.before(Version.V_2_0_0_beta1) && LEGACY_INCLUDE_IN_OBJECT.contains(metadataMapper.name())) { rootObjectMapper = rootObjectMapper.copyAndPutMapper(metadataMapper); } builder.put(metadataMapper.getClass(), metadataMapper); } this.root = rootObjectMapper; // keep root mappers sorted for consistent serialization Arrays.sort(metadataMappers, new Comparator<Mapper>() { @Override public int compare(Mapper o1, Mapper o2) { return o1.name().compareTo(o2.name()); } }); this.metadataMappersMap = builder.build(); this.sourceTransforms = sourceTransforms; this.meta = meta; }
Example 2
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 3
Source File: ParentFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
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 4
Source File: StringFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * The default position_increment_gap for a particular version of Elasticsearch. */ public static int positionIncrementGap(Version version) { if (version.before(Version.V_2_0_0_beta1)) { return POSITION_INCREMENT_GAP_PRE_2_0; } return POSITION_INCREMENT_GAP; }
Example 5
Source File: VersionUtils.java From crate with Apache License 2.0 | 5 votes |
/** * Get the released version before {@code version}. */ public static Version getPreviousVersion(Version version) { for (int i = RELEASED_VERSIONS.size() - 1; i >= 0; i--) { Version v = RELEASED_VERSIONS.get(i); if (v.before(version)) { return v; } } throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]"); }
Example 6
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 7
Source File: PluginInfo.java From crate with Apache License 2.0 | 4 votes |
/** * Reads the plugin descriptor file. * * @param path the path to the root directory for the plugin * @return the plugin info * @throws IOException if an I/O exception occurred reading the plugin descriptor */ public static PluginInfo readFromProperties(final Path path) throws IOException { final Path descriptor = path.resolve(ES_PLUGIN_PROPERTIES); final Map<String, String> propsMap; { final Properties props = new Properties(); try (InputStream stream = Files.newInputStream(descriptor)) { props.load(stream); } propsMap = props.stringPropertyNames().stream().collect(Collectors.toMap(Function.identity(), props::getProperty)); } final String name = propsMap.remove("name"); if (name == null || name.isEmpty()) { throw new IllegalArgumentException( "property [name] is missing in [" + descriptor + "]"); } final String description = propsMap.remove("description"); if (description == null) { throw new IllegalArgumentException( "property [description] is missing for plugin [" + name + "]"); } final String version = propsMap.remove("version"); if (version == null) { throw new IllegalArgumentException( "property [version] is missing for plugin [" + name + "]"); } final String esVersionString = propsMap.remove("elasticsearch.version"); if (esVersionString == null) { throw new IllegalArgumentException( "property [elasticsearch.version] is missing for plugin [" + name + "]"); } final Version esVersion = Version.fromInternalString(esVersionString); final String javaVersionString = propsMap.remove("java.version"); if (javaVersionString == null) { throw new IllegalArgumentException( "property [java.version] is missing for plugin [" + name + "]"); } JarHell.checkVersionFormat(javaVersionString); final String classname = propsMap.remove("classname"); if (classname == null) { throw new IllegalArgumentException( "property [classname] is missing for plugin [" + name + "]"); } final String extendedString = propsMap.remove("extended.plugins"); final List<String> extendedPlugins; if (extendedString == null) { extendedPlugins = Collections.emptyList(); } else { extendedPlugins = Arrays.asList(Strings.delimitedListToStringArray(extendedString, ",")); } final String hasNativeControllerValue = propsMap.remove("has.native.controller"); final boolean hasNativeController; if (hasNativeControllerValue == null) { hasNativeController = false; } else { switch (hasNativeControllerValue) { case "true": hasNativeController = true; break; case "false": hasNativeController = false; break; default: final String message = String.format( Locale.ROOT, "property [%s] must be [%s], [%s], or unspecified but was [%s]", "has_native_controller", "true", "false", hasNativeControllerValue); throw new IllegalArgumentException(message); } } if (esVersion.before(Version.ES_V_6_5_1)) { propsMap.remove("requires.keystore"); } if (propsMap.isEmpty() == false) { throw new IllegalArgumentException("Unknown properties in plugin descriptor: " + propsMap.keySet()); } return new PluginInfo(name, description, version, esVersion, javaVersionString, classname, extendedPlugins, hasNativeController); }
Example 8
Source File: BlobStoreRepository.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * In v2.0.0 we changed the matadata file format * @return true if legacy version should be used false otherwise */ public static boolean legacyMetaData(Version version) { return version.before(Version.V_2_0_0_beta1); }