public GeoGridAggregationBuilder precision(int precision) { this.precision = GeoUtils.checkPrecisionRange(precision); return this; }
/** * Parse a precision that can be expressed as an integer or a distance measure like "1km", "10m". * * The precision is expressed as a number between 1 and 12 and indicates the length of geohash * used to represent geo points. * * @param parser {@link XContentParser} to parse the value from * @return int representing precision */ public static int parsePrecision(XContentParser parser) throws IOException, ElasticsearchParseException { XContentParser.Token token = parser.currentToken(); if (token.equals(XContentParser.Token.VALUE_NUMBER)) { return XContentMapValues.nodeIntegerValue(parser.intValue()); } else { String precision = parser.text(); try { // we want to treat simple integer strings as precision levels, not distances return XContentMapValues.nodeIntegerValue(precision); } catch (NumberFormatException e) { // try to parse as a distance value final int parsedPrecision = GeoUtils.geoHashLevelsForPrecision(precision); try { return checkPrecisionRange(parsedPrecision); } catch (IllegalArgumentException e2) { // this happens when distance too small, so precision > 12. We'd like to see the original string throw new IllegalArgumentException("precision too high [" + precision + "]", e2); } } } }
public GeoGridAggregationBuilder precision(int precision) { this.precision = GeoUtils.checkPrecisionRange(precision); return this; }
public GeoGridAggregationBuilder precision(int precision) { this.precision = GeoUtils.checkPrecisionRange(precision); return this; }
/** * Parse a precision that can be expressed as an integer or a distance measure like "1km", "10m". * * The precision is expressed as a number between 1 and 12 and indicates the length of geohash * used to represent geo points. * * @param parser {@link XContentParser} to parse the value from * @return int representing precision */ public static int parsePrecision(XContentParser parser) throws IOException, ElasticsearchParseException { XContentParser.Token token = parser.currentToken(); if (token.equals(XContentParser.Token.VALUE_NUMBER)) { return XContentMapValues.nodeIntegerValue(parser.intValue()); } else { String precision = parser.text(); try { // we want to treat simple integer strings as precision levels, not distances return XContentMapValues.nodeIntegerValue(precision); } catch (NumberFormatException e) { // try to parse as a distance value final int parsedPrecision = GeoUtils.geoHashLevelsForPrecision(precision); try { return checkPrecisionRange(parsedPrecision); } catch (IllegalArgumentException e2) { // this happens when distance too small, so precision > 12. We'd like to see the original string throw new IllegalArgumentException("precision too high [" + precision + "]", e2); } } } }
/** * Parse a precision that can be expressed as an integer or a distance measure like "1km", "10m". * * The precision is expressed as a number between 1 and 12 and indicates the length of geohash * used to represent geo points. * * @param parser {@link XContentParser} to parse the value from * @return int representing precision */ public static int parsePrecision(XContentParser parser) throws IOException, ElasticsearchParseException { XContentParser.Token token = parser.currentToken(); if (token.equals(XContentParser.Token.VALUE_NUMBER)) { return XContentMapValues.nodeIntegerValue(parser.intValue()); } else { String precision = parser.text(); try { // we want to treat simple integer strings as precision levels, not distances return XContentMapValues.nodeIntegerValue(precision); } catch (NumberFormatException e) { // try to parse as a distance value final int parsedPrecision = GeoUtils.geoHashLevelsForPrecision(precision); try { return checkPrecisionRange(parsedPrecision); } catch (IllegalArgumentException e2) { // this happens when distance too small, so precision > 12. We'd like to see the original string throw new IllegalArgumentException("precision too high [" + precision + "]", e2); } } } }