# IllegalArgumentException\[can't sort on geo\_point field without using specific sorting feature, like geo\_distance\]

**URL:** <https://discuss.elastic.co/t/illegalargumentexception-cant-sort-on-geo-point-field-without-using-specific-sorting-feature-like-geo-distance/66385>\
**Category:** Elasticsearch\
**Created:** [November 17, 2016, 12:57pm UTC](https://discuss.elastic.co/t/illegalargumentexception-cant-sort-on-geo-point-field-without-using-specific-sorting-feature-like-geo-distance/66385 "2016-11-17T12:57:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinZ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevinz/32/13242_2.png) [@kevinZ](https://discuss.elastic.co/u/kevinZ)\
**Post date:** [November 17, 2016, 12:57pm UTC](https://discuss.elastic.co/t/illegalargumentexception-cant-sort-on-geo-point-field-without-using-specific-sorting-feature-like-geo-distance/66385/1 "2016-11-17T12:57:31Z")

</div>

I'm using `Elasticsearch v5.0` and want to query all cities within the specified radius. But it looks like I didn't specific sorting feature? Where to set that?  
Thank you 🙂

```auto
public static final int NB_MAX_RESULTS = 200;
public static final double ORIGIN_CITY_LON = 2.34; // Paris longitude(2.34)
public static final double ORIGIN_CITY_LAT = 48.86; // Paris lattitude(48.86)
public static final int DISTANCE_FROM_ORIGIN = 1000;
public static final DistanceUnit DISTANCE_UNIT = DistanceUnit.KILOMETERS;

```

```auto
QueryBuilder qb = geoDistanceQuery("coordinates")
			.point(Constant.ORIGIN_CITY_LAT, Constant.ORIGIN_CITY_LON)
			.distance(Constant.DISTANCE_FROM_ORIGIN, Constant.DISTANCE_UNIT)
			.optimizeBbox("memory")
			.geoDistance(GeoDistance.ARC);

SearchRequestBuilder searchRequestBuilder = client.prepareSearch("location").setTypes("city")
        .setQuery(qb)
        .setFrom(0)
        .setSize(Constant.NB_MAX_RESULTS)
        .addSort(SortBuilders.fieldSort("coordinates")
        .order(SortOrder.DESC))
        .addAggregation(AggregationBuilders.geoDistance("agg", new GeoPoint(Constant.ORIGIN_CITY_LAT, Constant.ORIGIN_CITY_LON))
                                           .field("coordinates")
                                           .unit(DistanceUnit.KILOMETERS)
					   .addRange(0, Constant.DISTANCE_FROM_ORIGIN));

SearchResponse sr = searchRequestBuilder.execute().actionGet();
Range agg = sr.getAggregations().get("agg");

System.out.println("------------------------------------------------------------------------------");
System.out.println("Search Results (reversed order):");
System.out.println("------------------------------------------------------------------------------");
for (SearchHit hit : sr.getHits()) {
    Map<String,SearchHitField> fields = hit.getFields();
    for(Map.Entry<String,SearchHitField> entry : fields.entrySet()){
        System.out.println(entry.getValue().getValues().get(0) +" ("+hit.getId()+") is "+hit.getSortValues()[0].toString()+" km far from origin");
    }
}
System.out.println("------------------------------------------------------------------------------");
System.out.println("GeoDistanceFacet results:");
System.out.println("------------------------------------------------------------------------------");

for (Range.Bucket entry : agg.getBuckets()) {
    System.out.println("Key: "+entry.getKeyAsString());
    System.out.println("Distance from origin: "+entry.getFrom()); // Distance from requested
    System.out.println("Distance to requested: "+entry.getTo()); // Distance to requested
    System.out.println("Number of results: "+entry.getDocCount()); // Doc count
}

```

This is the _ **ERROR** _ message:

```auto
Failed to execute phase [query], all shards failed; shardFailures {[T01_IzVqSaCvPJrGEfrnFw][location][0]: RemoteTransportException[[T01_IzV][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[can't sort on geo_point field without using specific sorting feature, like geo_distance]; }{[T01_IzVqSaCvPJrGEfrnFw][location][1]: RemoteTransportException[[T01_IzV][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[can't sort on geo_point field without using specific sorting feature, like geo_distance]; }{[T01_IzVqSaCvPJrGEfrnFw][location][2]: RemoteTransportException[[T01_IzV][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[can't sort on geo_point field without using specific sorting feature, like geo_distance]; }{[T01_IzVqSaCvPJrGEfrnFw][location][3]: RemoteTransportException[[T01_IzV][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[can't sort on geo_point field without using specific sorting feature, like geo_distance]; }{[T01_IzVqSaCvPJrGEfrnFw][location][4]: RemoteTransportException[[T01_IzV][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[can't sort on geo_point field without using specific sorting feature, like geo_distance]; }

```

This screenshot is about my index;  
 ![](https://us1.discourse-cdn.com/elastic/original/2X/1/112148aa1e3a8e1bac7cf746d0d9930045134edb.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 15, 2016, 12:57pm UTC](https://discuss.elastic.co/t/illegalargumentexception-cant-sort-on-geo-point-field-without-using-specific-sorting-feature-like-geo-distance/66385/2 "2016-12-15T12:57:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
