|
@@ -20,6 +20,7 @@
|
|
|
package org.elasticsearch.action.admin.indices.mapping.get;
|
|
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
+
|
|
|
import org.elasticsearch.action.ActionResponse;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.bytes.BytesReference;
|
|
@@ -31,14 +32,17 @@ import org.elasticsearch.common.xcontent.XContentHelper;
|
|
|
import org.elasticsearch.index.mapper.Mapper;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static java.util.Collections.unmodifiableMap;
|
|
|
+
|
|
|
/** Response object for {@link GetFieldMappingsRequest} API */
|
|
|
public class GetFieldMappingsResponse extends ActionResponse implements ToXContent {
|
|
|
|
|
|
- private ImmutableMap<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> mappings = ImmutableMap.of();
|
|
|
+ private Map<String, Map<String, Map<String, FieldMappingMetaData>>> mappings = ImmutableMap.of();
|
|
|
|
|
|
- GetFieldMappingsResponse(ImmutableMap<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> mappings) {
|
|
|
+ GetFieldMappingsResponse(Map<String, Map<String, Map<String, FieldMappingMetaData>>> mappings) {
|
|
|
this.mappings = mappings;
|
|
|
}
|
|
|
|
|
@@ -46,7 +50,7 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
|
|
|
}
|
|
|
|
|
|
/** returns the retrieved field mapping. The return map keys are index, type, field (as specified in the request). */
|
|
|
- public ImmutableMap<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> mappings() {
|
|
|
+ public Map<String, Map<String, Map<String, FieldMappingMetaData>>> mappings() {
|
|
|
return mappings;
|
|
|
}
|
|
|
|
|
@@ -57,11 +61,11 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
|
|
|
* @return FieldMappingMetaData for the requested field or null if not found.
|
|
|
*/
|
|
|
public FieldMappingMetaData fieldMappings(String index, String type, String field) {
|
|
|
- ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>> indexMapping = mappings.get(index);
|
|
|
+ Map<String, Map<String, FieldMappingMetaData>> indexMapping = mappings.get(index);
|
|
|
if (indexMapping == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- ImmutableMap<String, FieldMappingMetaData> typeMapping = indexMapping.get(type);
|
|
|
+ Map<String, FieldMappingMetaData> typeMapping = indexMapping.get(type);
|
|
|
if (typeMapping == null) {
|
|
|
return null;
|
|
|
}
|
|
@@ -70,10 +74,10 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
|
|
|
|
|
|
@Override
|
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
- for (Map.Entry<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> indexEntry : mappings.entrySet()) {
|
|
|
+ for (Map.Entry<String, Map<String, Map<String, FieldMappingMetaData>>> indexEntry : mappings.entrySet()) {
|
|
|
builder.startObject(indexEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
|
|
|
builder.startObject("mappings");
|
|
|
- for (Map.Entry<String, ImmutableMap<String, FieldMappingMetaData>> typeEntry : indexEntry.getValue().entrySet()) {
|
|
|
+ for (Map.Entry<String, Map<String, FieldMappingMetaData>> typeEntry : indexEntry.getValue().entrySet()) {
|
|
|
builder.startObject(typeEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
|
|
|
for (Map.Entry<String, FieldMappingMetaData> fieldEntry : typeEntry.getValue().entrySet()) {
|
|
|
builder.startObject(fieldEntry.getKey());
|
|
@@ -128,33 +132,33 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
|
|
|
public void readFrom(StreamInput in) throws IOException {
|
|
|
super.readFrom(in);
|
|
|
int size = in.readVInt();
|
|
|
- ImmutableMap.Builder<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> indexMapBuilder = ImmutableMap.builder();
|
|
|
+ Map<String, Map<String, Map<String, FieldMappingMetaData>>> indexMapBuilder = new HashMap<>(size);
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
String index = in.readString();
|
|
|
int typesSize = in.readVInt();
|
|
|
- ImmutableMap.Builder<String, ImmutableMap<String, FieldMappingMetaData>> typeMapBuilder = ImmutableMap.builder();
|
|
|
+ Map<String, Map<String, FieldMappingMetaData>> typeMapBuilder = new HashMap<>(typesSize);
|
|
|
for (int j = 0; j < typesSize; j++) {
|
|
|
String type = in.readString();
|
|
|
- ImmutableMap.Builder<String, FieldMappingMetaData> fieldMapBuilder = ImmutableMap.builder();
|
|
|
int fieldSize = in.readVInt();
|
|
|
+ Map<String, FieldMappingMetaData> fieldMapBuilder = new HashMap<>(fieldSize);
|
|
|
for (int k = 0; k < fieldSize; k++) {
|
|
|
fieldMapBuilder.put(in.readString(), new FieldMappingMetaData(in.readString(), in.readBytesReference()));
|
|
|
}
|
|
|
- typeMapBuilder.put(type, fieldMapBuilder.build());
|
|
|
+ typeMapBuilder.put(type, unmodifiableMap(fieldMapBuilder));
|
|
|
}
|
|
|
- indexMapBuilder.put(index, typeMapBuilder.build());
|
|
|
+ indexMapBuilder.put(index, unmodifiableMap(typeMapBuilder));
|
|
|
}
|
|
|
- mappings = indexMapBuilder.build();
|
|
|
+ mappings = unmodifiableMap(indexMapBuilder);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
super.writeTo(out);
|
|
|
out.writeVInt(mappings.size());
|
|
|
- for (Map.Entry<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> indexEntry : mappings.entrySet()) {
|
|
|
+ for (Map.Entry<String, Map<String, Map<String, FieldMappingMetaData>>> indexEntry : mappings.entrySet()) {
|
|
|
out.writeString(indexEntry.getKey());
|
|
|
out.writeVInt(indexEntry.getValue().size());
|
|
|
- for (Map.Entry<String, ImmutableMap<String, FieldMappingMetaData>> typeEntry : indexEntry.getValue().entrySet()) {
|
|
|
+ for (Map.Entry<String, Map<String, FieldMappingMetaData>> typeEntry : indexEntry.getValue().entrySet()) {
|
|
|
out.writeString(typeEntry.getKey());
|
|
|
out.writeVInt(typeEntry.getValue().size());
|
|
|
for (Map.Entry<String, FieldMappingMetaData> fieldEntry : typeEntry.getValue().entrySet()) {
|