org.elasticsearch.client.indices.GetMappingsResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-rest-high-level-client Show documentation
Show all versions of elasticsearch-rest-high-level-client Show documentation
Elasticsearch subproject :client:rest-high-level
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.client.indices;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentParser;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class GetMappingsResponse {
static final ParseField MAPPINGS = new ParseField("mappings");
private Map mappings;
public GetMappingsResponse(Map mappings) {
this.mappings = mappings;
}
public Map mappings() {
return mappings;
}
public static GetMappingsResponse fromXContent(XContentParser parser) throws IOException {
if (parser.currentToken() == null) {
parser.nextToken();
}
XContentParserUtils.ensureExpectedToken(parser.currentToken(), XContentParser.Token.START_OBJECT, parser);
Map parts = parser.map();
Map mappings = new HashMap<>();
for (Map.Entry entry : parts.entrySet()) {
String indexName = entry.getKey();
assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass();
@SuppressWarnings("unchecked")
final Map fieldMappings = (Map) ((Map) entry.getValue()).get(
MAPPINGS.getPreferredName()
);
mappings.put(indexName, new MappingMetadata(MapperService.SINGLE_MAPPING_NAME, fieldMappings));
}
return new GetMappingsResponse(mappings);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy