本文整理汇总了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);
}