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