Sorting on a GeoPoint throws a ClassCastException

Hi everybody,

I'm trying to add a sort on a geo_point field but get a ClassCastException.


The query:

{
"query": {
"match_all": {}
},
"size": 10,
"sort": {
"dealerLocation": {
"order": "asc"
}
}
}


the mapping

{
"usedcar": {
"properties": {
"dealerId": {
"type": "string"
},
"dealerLocation": {
"type": "geo_point"
}
}
}
}


the result

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], total failure; shardFailures {[6qz3pf-nTp-raW4PxwknnQ][en_gb][3]:
QueryPhaseExecutionException[[en_gb][3]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@1bd5b5b>]: Query
Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData];
}{[6qz3pf-nTp-raW4PxwknnQ][en_gb][0]:
QueryPhaseExecutionException[[en_gb][0]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@1e78c5e>]: Query
Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData];
}{[6qz3pf-nTp-raW4PxwknnQ][en_gb][4]:
QueryPhaseExecutionException[[en_gb][4]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@b09747>]: Query
Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData]; }]",
"status": 500
}

Any idea ?

Regards,

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

If you want to use geo sorting you need to use the "_geo_distance" format
as is described here:
http://www.elasticsearch.org/guide/reference/api/search/sort/

I expect that the following works:
{
"query": {
"match_all": {}
},
"size": 10,
"sort": {
"_geo_distance" : {
"dealerLocation" : [-70, 40], // <-- the point to calculate
the distance from
"order" : "asc",
"unit" : "km"
}
}
}

What Elasticsearch version are you using? Seems like regular field sorting
doesn't like to sort on geo_point. A better error message would be nicer.

Martijn

On 12 June 2013 17:48, Mehrez Marouani mehrez.marouani@gmail.com wrote:

Hi everybody,

I'm trying to add a sort on a geo_point field but get a ClassCastException.


The query:

{
"query": {
"match_all": {}
},
"size": 10,
"sort": {
"dealerLocation": {
"order": "asc"
}
}
}


the mapping

{
"usedcar": {
"properties": {
"dealerId": {
"type": "string"
},
"dealerLocation": {
"type": "geo_point"
}
}
}
}


the result

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], total failure; shardFailures {[6qz3pf-nTp-raW4PxwknnQ][en_gb][3]:
QueryPhaseExecutionException[[en_gb][3]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@1bd5b5b>]:
Query Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData];
}{[6qz3pf-nTp-raW4PxwknnQ][en_gb][0]:
QueryPhaseExecutionException[[en_gb][0]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@1e78c5e>]:
Query Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData];
}{[6qz3pf-nTp-raW4PxwknnQ][en_gb][4]:
QueryPhaseExecutionException[[en_gb][4]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@b09747>]:
Query Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData]; }]",
"status": 500
}

Any idea ?

Regards,

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks Martijn.

I've already solved the problem by using the latest version.
I was using 0.20.1 version.

Regards,

On Thursday, June 13, 2013 4:50:54 PM UTC+2, Martijn v Groningen wrote:

If you want to use geo sorting you need to use the "_geo_distance" format
as is described here:
http://www.elasticsearch.org/guide/reference/api/search/sort/

I expect that the following works:
{
"query": {
"match_all": {}
},
"size": 10,
"sort": {
"_geo_distance" : {
"dealerLocation" : [-70, 40], // <-- the point to
calculate the distance from
"order" : "asc",
"unit" : "km"
}
}
}

What Elasticsearch version are you using? Seems like regular field sorting
doesn't like to sort on geo_point. A better error message would be nicer.

Martijn

On 12 June 2013 17:48, Mehrez Marouani <mehrez....@gmail.com <javascript:>

wrote:

Hi everybody,

I'm trying to add a sort on a geo_point field but get a
ClassCastException.


The query:

{
"query": {
"match_all": {}
},
"size": 10,
"sort": {
"dealerLocation": {
"order": "asc"
}
}
}


the mapping

{
"usedcar": {
"properties": {
"dealerId": {
"type": "string"
},
"dealerLocation": {
"type": "geo_point"
}
}
}
}


the result

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], total failure; shardFailures {[6qz3pf-nTp-raW4PxwknnQ][en_gb][3]:
QueryPhaseExecutionException[[en_gb][3]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@1bd5b5b>]: Query
Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData];
}{[6qz3pf-nTp-raW4PxwknnQ][en_gb][0]:
QueryPhaseExecutionException[[en_gb][0]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@1e78c5e>]: Query
Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData];
}{[6qz3pf-nTp-raW4PxwknnQ][en_gb][4]:
QueryPhaseExecutionException[[en_gb][4]:
query[ConstantScore(NotDeleted(cache(_type:usedcar)))],from[0],size[10],sort[<custom:"dealerLocation":
org.elasticsearch.index.mapper.geo.GeoPointFieldDataType$1@b09747>]: Query
Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.mapper.geo.SingleValueGeoPointFieldData
cannot be cast to
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData]; }]",
"status": 500
}

Any idea ?

Regards,

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.