Skip to content

Commit

Permalink
Removed changes from MappingMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Jan 18, 2024
1 parent 8389572 commit b2aab09
Showing 1 changed file with 1 addition and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MappingLookup;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;

Expand All @@ -44,15 +42,10 @@ public class MappingMetadata implements SimpleDiffable<MappingMetadata> {

private final boolean routingRequired;

private final Map<String, Set<String>> fieldsForModels;

public MappingMetadata(DocumentMapper docMapper) {
this.type = docMapper.type();
this.source = docMapper.mappingSource();
this.routingRequired = docMapper.routingFieldMapper().required();

MappingLookup mappingLookup = docMapper.mappers();
this.fieldsForModels = mappingLookup != null ? mappingLookup.getFieldsForModels() : Map.of();
}

@SuppressWarnings({ "this-escape", "unchecked" })
Expand All @@ -64,7 +57,6 @@ public MappingMetadata(CompressedXContent mapping) {
}
this.type = mappingMap.keySet().iterator().next();
this.routingRequired = routingRequired((Map<String, Object>) mappingMap.get(this.type));
this.fieldsForModels = Map.of();
}

@SuppressWarnings({ "this-escape", "unchecked" })
Expand All @@ -80,7 +72,6 @@ public MappingMetadata(String type, Map<String, Object> mapping) {
withoutType = (Map<String, Object>) mapping.get(type);
}
this.routingRequired = routingRequired(withoutType);
this.fieldsForModels = Map.of();
}

public static void writeMappingMetadata(StreamOutput out, Map<String, MappingMetadata> mappings) throws IOException {
Expand Down Expand Up @@ -167,19 +158,12 @@ public String getSha256() {
return source.getSha256();
}

public Map<String, Set<String>> getFieldsForModels() {
return fieldsForModels;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(type());
source().writeTo(out);
// routing
out.writeBoolean(routingRequired);
if (out.getTransportVersion().onOrAfter(TransportVersions.SEMANTIC_TEXT_FIELD_ADDED)) {
out.writeMap(fieldsForModels, StreamOutput::writeStringCollection);
}
}

@Override
Expand All @@ -192,25 +176,19 @@ public boolean equals(Object o) {
if (Objects.equals(this.routingRequired, that.routingRequired) == false) return false;
if (source.equals(that.source) == false) return false;
if (type.equals(that.type) == false) return false;
if (Objects.equals(this.fieldsForModels, that.fieldsForModels) == false) return false;

return true;
}

@Override
public int hashCode() {
return Objects.hash(type, source, routingRequired, fieldsForModels);
return Objects.hash(type, source, routingRequired);
}

public MappingMetadata(StreamInput in) throws IOException {
type = in.readString();
source = CompressedXContent.readCompressedString(in);
routingRequired = in.readBoolean();
if (in.getTransportVersion().onOrAfter(TransportVersions.SEMANTIC_TEXT_FIELD_ADDED)) {
fieldsForModels = in.readMap(StreamInput::readString, i -> i.readCollectionAsImmutableSet(StreamInput::readString));
} else {
fieldsForModels = Map.of();
}
}

public static Diff<MappingMetadata> readDiffFrom(StreamInput in) throws IOException {
Expand Down

0 comments on commit b2aab09

Please sign in to comment.