public Builder putMapping(String mappingType, String mappingSource) throws IOException { mappings.put(mappingType, new CompressedXContent(mappingSource)); return this; }
public MappingMetaData(CompressedXContent mapping) throws IOException { this.source = mapping; Map<String, Object> mappingMap = XContentHelper.convertToMap(mapping.compressedReference(), true).v2(); if (mappingMap.size() != 1) { throw new IllegalStateException("Can't derive type from mapping, no root type: " + mapping.string()); } this.type = mappingMap.keySet().iterator().next(); initMappers((Map<String, Object>) mappingMap.get(this.type)); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CompressedXContent that = (CompressedXContent) o; if (Arrays.equals(compressed(), that.compressed())) { return true; } if (crc32 != that.crc32) { return false; } return Arrays.equals(uncompressed(), that.uncompressed()); }
private void assertConsistent() { assert CompressorFactory.compressor(new BytesArray(bytes)) != null; assert this.crc32 == crc32(new BytesArray(uncompressed())); }
/** * Create a {@link CompressedXContent} out of a serialized {@link ToXContent} * that may already be compressed. */ public CompressedXContent(BytesReference data) throws IOException { Compressor compressor = CompressorFactory.compressor(data); if (compressor != null) { // already compressed... this.bytes = BytesReference.toBytes(data); this.crc32 = crc32(new BytesArray(uncompressed())); } else { BytesStreamOutput out = new BytesStreamOutput(); try (OutputStream compressedOutput = CompressorFactory.COMPRESSOR.streamOutput(out)) { data.writeTo(compressedOutput); } this.bytes = BytesReference.toBytes(out.bytes()); this.crc32 = crc32(data); } assertConsistent(); }
if (logger.isDebugEnabled() && incomingMappingSource.compressed().length < 512) { logger.debug("[{}] {} mapping [{}], source [{}]", index(), op, mappingType, incomingMappingSource.string()); } else if (logger.isTraceEnabled()) { logger.trace("[{}] {} mapping [{}], source [{}]", index(), op, mappingType, incomingMappingSource.string()); } else { logger.debug("[{}] {} mapping [{}] (source suppressed due to length, use TRACE level if needed)", if (documentMapper(mappingType).mappingSource().equals(incomingMappingSource) == false) { logger.debug("[{}] parsed mapping [{}], and got different sources\noriginal:\n{}\nparsed:\n{}", index(), mappingType, incomingMappingSource, documentMapper(mappingType).mappingSource());
public MappingMetaData(StreamInput in) throws IOException { type = in.readString(); source = CompressedXContent.readCompressedString(in); // routing routing = new Routing(in.readBoolean()); if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // timestamp boolean enabled = in.readBoolean(); if (enabled) { throw new IllegalArgumentException("_timestamp may not be enabled"); } in.readString(); // format in.readOptionalString(); // defaultTimestamp in.readOptionalBoolean(); // ignoreMissing } hasParentField = in.readBoolean(); }
private CompressedXContent(byte[] compressed, int crc32) { this.bytes = compressed; this.crc32 = crc32; assertConsistent(); }
@Override public int hashCode() { int result = alias != null ? alias.hashCode() : 0; result = 31 * result + (filter != null ? filter.hashCode() : 0); result = 31 * result + (indexRouting != null ? indexRouting.hashCode() : 0); result = 31 * result + (searchRouting != null ? searchRouting.hashCode() : 0); result = 31 * result + (writeIndex != null ? writeIndex.hashCode() : 0); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AliasMetaData that = (AliasMetaData) o; if (alias != null ? !alias.equals(that.alias) : that.alias != null) return false; if (filter != null ? !filter.equals(that.filter) : that.filter != null) return false; if (indexRouting != null ? !indexRouting.equals(that.indexRouting) : that.indexRouting != null) return false; if (searchRouting != null ? !searchRouting.equals(that.searchRouting) : that.searchRouting != null) return false; if (writeIndex != null ? writeIndex != that.writeIndex : that.writeIndex != null) return false; return true; }
@Override public String toString() { return string(); } }
templateNames.add(template.getName()); for (ObjectObjectCursor<String, CompressedXContent> cursor : template.mappings()) { String mappingString = cursor.value.string(); if (mappings.containsKey(cursor.key)) { XContentHelper.mergeDefaults(mappings.get(cursor.key), aliasValidator.validateAliasFilter(aliasMetaData.alias(), aliasMetaData.filter().uncompressed(), queryShardContext, xContentRegistry);
JsonNode rootNode; try { rootNode = objecMapper.readTree(mappingMetaData.source().uncompressed());
private ClusterState applyRequest(ClusterState currentState, PutMappingClusterStateUpdateRequest request, Map<Index, MapperService> indexMapperServices) throws IOException { String mappingType = request.type(); CompressedXContent mappingUpdateSource = new CompressedXContent(request.source()); final MetaData metaData = currentState.metaData(); final List<IndexMetaData> updateList = new ArrayList<>(); if (existingSource.equals(updatedSource)) {
/** * Converts the serialized compressed form of the mappings into a parsed map. */ public Map<String, Object> sourceAsMap() throws ElasticsearchParseException { Map<String, Object> mapping = XContentHelper.convertToMap(source.compressedReference(), true).v2(); if (mapping.size() == 1 && mapping.containsKey(type())) { // the type name is the root value, reduce it mapping = (Map<String, Object>) mapping.get(type()); } return mapping; }
/** * Create a {@link CompressedXContent} out of a serialized {@link ToXContent} * that may already be compressed. */ public CompressedXContent(BytesReference data) throws IOException { Compressor compressor = CompressorFactory.compressor(data); if (compressor != null) { // already compressed... this.bytes = BytesReference.toBytes(data); this.crc32 = crc32(new BytesArray(uncompressed())); } else { BytesStreamOutput out = new BytesStreamOutput(); try (OutputStream compressedOutput = CompressorFactory.COMPRESSOR.streamOutput(out)) { data.writeTo(compressedOutput); } this.bytes = BytesReference.toBytes(out.bytes()); this.crc32 = crc32(data); } assertConsistent(); }
private void assertConsistent() { assert CompressorFactory.compressor(new BytesArray(bytes)) != null; assert this.crc32 == crc32(new BytesArray(uncompressed())); }
public AliasMetaData(StreamInput in) throws IOException { alias = in.readString(); if (in.readBoolean()) { filter = CompressedXContent.readCompressedString(in); } else { filter = null; } if (in.readBoolean()) { indexRouting = in.readString(); } else { indexRouting = null; } if (in.readBoolean()) { searchRouting = in.readString(); searchRoutingValues = Collections.unmodifiableSet(Sets.newHashSet(Strings.splitStringByCommaToArray(searchRouting))); } else { searchRouting = null; searchRoutingValues = emptySet(); } if (in.getVersion().onOrAfter(Version.V_6_4_0)) { writeIndex = in.readOptionalBoolean(); } else { writeIndex = null; } }
/** * Create a {@link CompressedXContent} out of a {@link ToXContent} instance. */ public CompressedXContent(ToXContent xcontent, XContentType type, ToXContent.Params params) throws IOException { BytesStreamOutput bStream = new BytesStreamOutput(); OutputStream compressedStream = CompressorFactory.COMPRESSOR.streamOutput(bStream); CRC32 crc32 = new CRC32(); OutputStream checkedStream = new CheckedOutputStream(compressedStream, crc32); try (XContentBuilder builder = XContentFactory.contentBuilder(type, checkedStream)) { builder.startObject(); xcontent.toXContent(builder, params); builder.endObject(); } this.bytes = BytesReference.toBytes(bStream.bytes()); this.crc32 = (int) crc32.getValue(); assertConsistent(); }
@Override public int hashCode() { int result = type.hashCode(); result = 31 * result + source.hashCode(); result = 31 * result + routing.hashCode(); return result; }