mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-07 21:48:39 +00:00
simplify parsing code
This commit is contained in:
parent
41e4ee22e6
commit
1d63ff64c7
@ -30,7 +30,6 @@ import org.elasticsearch.common.settings.ImmutableSettings;
|
|||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
|
||||||
import org.elasticsearch.index.AbstractIndexComponent;
|
import org.elasticsearch.index.AbstractIndexComponent;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.analysis.AnalysisService;
|
import org.elasticsearch.index.analysis.AnalysisService;
|
||||||
@ -47,7 +46,6 @@ import org.elasticsearch.index.mapper.object.RootObjectMapper;
|
|||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
import org.elasticsearch.index.similarity.SimilarityLookupService;
|
import org.elasticsearch.index.similarity.SimilarityLookupService;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.index.mapper.MapperBuilders.doc;
|
import static org.elasticsearch.index.mapper.MapperBuilders.doc;
|
||||||
@ -237,21 +235,15 @@ public class DocumentMapperParser extends AbstractIndexComponent {
|
|||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
private Tuple<String, Map<String, Object>> extractMapping(String type, String source) throws MapperParsingException {
|
private Tuple<String, Map<String, Object>> extractMapping(String type, String source) throws MapperParsingException {
|
||||||
Map<String, Object> root;
|
Map<String, Object> root;
|
||||||
XContentParser xContentParser = null;
|
|
||||||
try {
|
try {
|
||||||
xContentParser = XContentFactory.xContent(source).createParser(source);
|
root = XContentFactory.xContent(source).createParser(source).mapOrderedAndClose();
|
||||||
root = xContentParser.mapOrdered();
|
} catch (Exception e) {
|
||||||
} catch (IOException e) {
|
throw new MapperParsingException("failed to parse mapping definition", e);
|
||||||
throw new MapperParsingException("Failed to parse mapping definition", e);
|
|
||||||
} finally {
|
|
||||||
if (xContentParser != null) {
|
|
||||||
xContentParser.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we always assume the first and single key is the mapping type root
|
// we always assume the first and single key is the mapping type root
|
||||||
if (root.keySet().size() != 1) {
|
if (root.keySet().size() != 1) {
|
||||||
throw new MapperParsingException("Mapping must have the `type` as the root object");
|
throw new MapperParsingException("mapping must have the `type` as the root object");
|
||||||
}
|
}
|
||||||
|
|
||||||
String rootName = root.keySet().iterator().next();
|
String rootName = root.keySet().iterator().next();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user