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


Java DistanceUnit.parse方法代码示例

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


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

示例1: parse

import org.elasticsearch.common.unit.DistanceUnit; //导入方法依赖的package包/类
/**
 * Construct a builder from XContent, which usually comes from the JSON
 * query API
 */
static GeoHeatmapAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
    XContentParser parser = context.parser();

    XContentParser.Token token;
    String currentFieldName = null;
    String field = null;
    GeoShapeQueryBuilder geom = null;
    Integer maxCells = null;
    Double distErr = null;
    Double distErrPct = null;
    Integer gridLevel = null;

    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("field".equals(currentFieldName)) {
                field = parser.text();
            } else if (DIST_ERR_FIELD.match(currentFieldName)) {
                distErr = DistanceUnit.parse(parser.text(), DistanceUnit.DEFAULT, DistanceUnit.DEFAULT);
            }
        } else if (token.isValue()) {
            if (MAX_CELLS_FIELD.match(currentFieldName)) {
                maxCells = parser.intValue();
            } else if (DIST_ERR_PCT_FIELD.match(currentFieldName)) {
                distErrPct = parser.doubleValue();
            } else if (GRID_LEVEL_FIELD.match(currentFieldName)) {
                gridLevel = parser.intValue();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            if (GEOM_FIELD.match(currentFieldName)) {
                geom = (GeoShapeQueryBuilder) context.parseInnerQueryBuilder()
                        .filter(qb -> qb.getWriteableName().equals(GeoShapeQueryBuilder.NAME)).orElse(null);
            } else {
                throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].",
                        parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.VALUE_NULL) {
            if (!MAX_CELLS_FIELD.match(currentFieldName)
                    && !DIST_ERR_PCT_FIELD.match(currentFieldName)
                    && !GRID_LEVEL_FIELD.match(currentFieldName)
                    && !GEOM_FIELD.match(currentFieldName)) {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(),
                    "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
        }
    }

    if (field == null) {
        throw new ParsingException(null, "Missing required field [field] for geo_heatmap aggregation [" + aggregationName + "]");
    }
    return new GeoHeatmapAggregationBuilder(aggregationName).geom(geom).field(field).maxCells(maxCells)
            .distErr(distErr).distErrPct(distErrPct).gridLevel(gridLevel);
}
 
开发者ID:boundlessgeo,项目名称:elasticsearch-heatmap,代码行数:65,代码来源:GeoHeatmapAggregationBuilder.java


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