--- title: "Geo distance 需要指定距离参数——如何解决此 Elasticsearch 异常" date: 2026-03-11 lastmod: 2026-03-11 description: "当 Elasticsearch 中的 geo_distance 查询未指定 'distance' 参数时会出现此错误。本文介绍如何解决该异常。" tags: ["地理查询", "geo_distance", "距离参数", "查询异常", "Elasticsearch"] summary: " 版本: 6.8-8.9 简而言之,当在 Elasticsearch 的 geo_distance 查询中未指定 distance 参数时,就会出现此错误。geo_distance 查询用于查找距离地理点一定范围内的文档。要解决此问题,您需要在查询中指定 distance 参数。可以通过在查询中添加 distance 字段并为其提供值来实现。该值应该是一个数字后跟距离单位,例如 “12km” 或 “5mi”。 日志上下文 # 日志 “geo_distance requires ‘distance’ to be specified” 的类名是 GeoDistanceQueryBuilder.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: } } } if (vDistance == null) { throw new ParsingException(parser.getTokenLocation(); "geo_distance requires 'distance' to be specified"); } GeoDistanceQueryBuilder qb = new GeoDistanceQueryBuilder(fieldName); if (vDistance instanceof Number) { qb.distance(((Number) vDistance).doubleValue(); unit); " --- > **版本:** 6.8-8.9 简而言之,当在 Elasticsearch 的 `geo_distance` 查询中未指定 `distance` 参数时,就会出现此错误。`geo_distance` 查询用于查找距离地理点一定范围内的文档。要解决此问题,您需要在查询中指定 `distance` 参数。可以通过在查询中添加 `distance` 字段并为其提供值来实现。该值应该是一个数字后跟距离单位,例如 "12km" 或 "5mi"。 日志上下文 ----------- 日志 "geo\_distance requires 'distance' to be specified" 的类名是 [GeoDistanceQueryBuilder.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: ```java } } } if (vDistance == null) { throw new ParsingException(parser.getTokenLocation(); "geo_distance requires 'distance' to be specified"); } GeoDistanceQueryBuilder qb = new GeoDistanceQueryBuilder(fieldName); if (vDistance instanceof Number) { qb.distance(((Number) vDistance).doubleValue(); unit); ```