当前位置: 首页>>代码示例>>Java>>正文


Java XContentHelper.mergeDefaults方法代码示例

本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentHelper.mergeDefaults方法的典型用法代码示例。如果您正苦于以下问题:Java XContentHelper.mergeDefaults方法的具体用法?Java XContentHelper.mergeDefaults怎么用?Java XContentHelper.mergeDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.xcontent.XContentHelper的用法示例。


在下文中一共展示了XContentHelper.mergeDefaults方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addMappings

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
private void addMappings(Map<String, Map<String, Object>> mappings, File mappingsDir) {
    File[] mappingsFiles = mappingsDir.listFiles();
    for (File mappingFile : mappingsFiles) {
        if (mappingFile.isHidden()) {
            continue;
        }
        int lastDotIndex = mappingFile.getName().lastIndexOf('.');
        String mappingType = lastDotIndex != -1 ? mappingFile.getName().substring(0, lastDotIndex) : mappingFile.getName();
        try {
            String mappingSource = Streams.copyToString(new InputStreamReader(new FileInputStream(mappingFile), Charsets.UTF_8));
            if (mappings.containsKey(mappingType)) {
                XContentHelper.mergeDefaults(mappings.get(mappingType), parseMapping(mappingSource));
            } else {
                mappings.put(mappingType, parseMapping(mappingSource));
            }
        } catch (Exception e) {
            logger.warn("failed to read / parse mapping [" + mappingType + "] from location [" + mappingFile + "], ignoring...", e);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:TransportBulkCreateIndicesAction.java

示例2: addMappings

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
private void addMappings(Map<String, Map<String, Object>> mappings, Path mappingsDir) throws IOException {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(mappingsDir)) {
        for (Path mappingFile : stream) {
            final String fileName = mappingFile.getFileName().toString();
            if (FileSystemUtils.isHidden(mappingFile)) {
                continue;
            }
            int lastDotIndex = fileName.lastIndexOf('.');
            String mappingType = lastDotIndex != -1 ? mappingFile.getFileName().toString().substring(0, lastDotIndex) : mappingFile.getFileName().toString();
            try (BufferedReader reader = Files.newBufferedReader(mappingFile, Charsets.UTF_8)) {
                String mappingSource = Streams.copyToString(reader);
                if (mappings.containsKey(mappingType)) {
                    XContentHelper.mergeDefaults(mappings.get(mappingType), parseMapping(mappingSource));
                } else {
                    mappings.put(mappingType, parseMapping(mappingSource));
                }
            } catch (Exception e) {
                logger.warn("failed to read / parse mapping [" + mappingType + "] from location [" + mappingFile + "], ignoring...", e);
            }
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:MetaDataCreateIndexService.java

示例3: testMergingListValuesAreMapsOfOne

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
public void testMergingListValuesAreMapsOfOne() {
    Map<String, Object> defaults = getMap("test", getList(getNamedMap("name1", "t1", "1"), getNamedMap("name2", "t2", "2")));
    Map<String, Object> content = getMap("test", getList(getNamedMap("name2", "t3", "3"), getNamedMap("name4", "t4", "4")));
    Map<String, Object> expected = getMap("test",
            getList(getNamedMap("name2", "t2", "2", "t3", "3"), getNamedMap("name4", "t4", "4"), getNamedMap("name1", "t1", "1")));

    XContentHelper.mergeDefaults(content, defaults);

    assertThat(content, Matchers.equalTo(expected));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:XContentHelperTests.java

示例4: parse

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
private DocumentMapper parse(String type, Map<String, Object> mapping, String defaultSource) throws MapperParsingException {
    if (type == null) {
        throw new MapperParsingException("Failed to derive type");
    }

    if (defaultSource != null) {
        Tuple<String, Map<String, Object>> t = extractMapping(MapperService.DEFAULT_MAPPING, defaultSource);
        if (t.v2() != null) {
            XContentHelper.mergeDefaults(mapping, t.v2());
        }
    }


    Mapper.TypeParser.ParserContext parserContext = parserContext(type);
    // parse RootObjectMapper
    DocumentMapper.Builder docBuilder = new DocumentMapper.Builder(
            (RootObjectMapper.Builder) rootObjectTypeParser.parse(type, mapping, parserContext), mapperService);
    Iterator<Map.Entry<String, Object>> iterator = mapping.entrySet().iterator();
    // parse DocumentMapper
    while(iterator.hasNext()) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = entry.getKey();
        Object fieldNode = entry.getValue();

        MetadataFieldMapper.TypeParser typeParser = rootTypeParsers.get(fieldName);
        if (typeParser != null) {
            iterator.remove();
            if (false == fieldNode instanceof Map) {
                throw new IllegalArgumentException("[_parent] must be an object containing [type]");
            }
            Map<String, Object> fieldNodeMap = (Map<String, Object>) fieldNode;
            docBuilder.put(typeParser.parse(fieldName, fieldNodeMap, parserContext));
            fieldNodeMap.remove("type");
            checkNoRemainingFields(fieldName, fieldNodeMap, parserContext.indexVersionCreated());
        }
    }

    Map<String, Object> meta = (Map<String, Object>) mapping.remove("_meta");
    if (meta != null) {
        // It may not be required to copy meta here to maintain immutability
        // but the cost is pretty low here.
        docBuilder.meta(unmodifiableMap(new HashMap<>(meta)));
    }

    checkNoRemainingFields(mapping, parserContext.indexVersionCreated(), "Root mapping definition has unsupported parameters: ");

    return docBuilder.build(mapperService);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:50,代码来源:DocumentMapperParser.java

示例5: parse

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
private DocumentMapper parse(String type, Map<String, Object> mapping, String defaultSource) throws MapperParsingException {
    if (type == null) {
        throw new MapperParsingException("Failed to derive type");
    }

    if (defaultSource != null) {
        Tuple<String, Map<String, Object>> t = extractMapping(MapperService.DEFAULT_MAPPING, defaultSource);
        if (t.v2() != null) {
            XContentHelper.mergeDefaults(mapping, t.v2());
        }
    }


    Mapper.TypeParser.ParserContext parserContext = parserContext(type);
    // parse RootObjectMapper
    DocumentMapper.Builder docBuilder = doc((RootObjectMapper.Builder) rootObjectTypeParser.parse(type, mapping, parserContext), mapperService);
    Iterator<Map.Entry<String, Object>> iterator = mapping.entrySet().iterator();
    // parse DocumentMapper
    while(iterator.hasNext()) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();

        if ("transform".equals(fieldName)) {
            deprecationLogger.deprecated("Mapping transform is deprecated and will be removed in the next major version");
            if (fieldNode instanceof Map) {
                parseTransform(docBuilder, (Map<String, Object>) fieldNode, parserContext.indexVersionCreated());
            } else if (fieldNode instanceof List) {
                for (Object transformItem: (List)fieldNode) {
                    if (!(transformItem instanceof Map)) {
                        throw new MapperParsingException("Elements of transform list must be objects but one was:  " + fieldNode);
                    }
                    parseTransform(docBuilder, (Map<String, Object>) transformItem, parserContext.indexVersionCreated());
                }
            } else {
                throw new MapperParsingException("Transform must be an object or an array but was:  " + fieldNode);
            }
            iterator.remove();
        } else {
            MetadataFieldMapper.TypeParser typeParser = rootTypeParsers.get(fieldName);
            if (typeParser != null) {
                iterator.remove();
                Map<String, Object> fieldNodeMap = (Map<String, Object>) fieldNode;
                docBuilder.put((MetadataFieldMapper.Builder)typeParser.parse(fieldName, fieldNodeMap, parserContext));
                fieldNodeMap.remove("type");
                checkNoRemainingFields(fieldName, fieldNodeMap, parserContext.indexVersionCreated());
            }
        }
    }

    ImmutableMap<String, Object> attributes = ImmutableMap.of();
    if (mapping.containsKey("_meta")) {
        attributes = ImmutableMap.copyOf((Map<String, Object>) mapping.remove("_meta"));
    }
    docBuilder.meta(attributes);

    checkNoRemainingFields(mapping, parserContext.indexVersionCreated(), "Root mapping definition has unsupported parameters: ");

    return docBuilder.build(mapperService);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:62,代码来源:DocumentMapperParser.java


注:本文中的org.elasticsearch.common.xcontent.XContentHelper.mergeDefaults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。