Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geoSort should create GeoDistanceSortDefinition with empty geohashes #703

Closed
saucam opened this issue Jan 5, 2017 · 1 comment
Closed

Comments

@saucam
Copy link

saucam commented Jan 5, 2017

When geoSort is used with GeoPoint parameters:

geoSort("location") points List(new GeoPoint(lat, lon)) unit KILOMETERS geoDistance sortMode order SortOrder.DESC

it throws:

Geo distance sorting needs at least one point.
java.lang.IllegalArgumentException: Geo distance sorting needs at least one point.
	at org.elasticsearch.search.sort.GeoDistanceSortBuilder.<init>(GeoDistanceSortBuilder.java:130)
	at org.elasticsearch.search.sort.SortBuilders.geoDistanceSort(SortBuilders.java:88)
	at com.sksamuel.elastic4s.searches.sort.GeoDistanceSortDefinition.<init>(GeoDistanceSortDefinition.scala:13)
	at com.sksamuel.elastic4s.searches.sort.SortDsl$GeoSortExpectsPoints.points(SortDsl.scala:27)

This is because internally this goes to :

def points(points: Iterable[GeoPoint]): GeoDistanceSortDefinition =
      new GeoDistanceSortDefinition(field, Nil, points.toSeq)

which calls

val builder = SortBuilders.geoDistanceSort(field, geohashes: _*).points(points: _*)

inside GeoDistanceSortDefinition
This calls a constructor that always expects a geohash in GeoDistanceSortBuilder,
instead of using the other constructor that expects GeoPoints

 public GeoDistanceSortBuilder(String fieldName, String ... geohashes) {
        if (geohashes.length == 0) {
            throw new IllegalArgumentException("Geo distance sorting needs at least one point.");
        }
...
@saucam
Copy link
Author

saucam commented Jan 5, 2017

#704

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant