curl -X GET 'http://localhost:9200/users/user/_search?pretty' -d '{
"script_fields":{
"distance":{
"params":{
"lat":23.1191,
"lon":113.31
},
"script":"doc[\"location\"].distanceInKm(lat, lon)",
"lang":"groovy"
}
}
}
'
# 2015-08-31T14:29:46+08:00 [200] (0.005s)
#
# {
# "took":2,
# "timed_out":false,
# "_shards":{
# "total":5,
# "successful":5,
# "failed":0
# },
# "hits":{
# "total":11,
# "max_score":1.0,
# "hits":[
# {
# "_index":"users",
# "_type":"user",
# "_id":"4",
# "_score":1.0,
# "fields":{
# "distance":[
# 12873.486133286819
# ]
#
# }
# },
# ...
请问如何用 fields.distance 进行排序?
在 sort 中,不知道如何取到 distance 的值,所以也就无法写出 sort 子句,求解惑!!