Skip to content

Instantly share code, notes, and snippets.

@tobinbc
Last active February 16, 2020 10:52
Show Gist options
  • Save tobinbc/884e499abb5615e64ccfe1756c6f63f3 to your computer and use it in GitHub Desktop.
Save tobinbc/884e499abb5615e64ccfe1756c6f63f3 to your computer and use it in GitHub Desktop.
#set( $indexPath = "/tree/_doc/_search" )
#set( $input = $ctx.args.input)
#set( $distance = $util.defaultIfNull($input.km, 10) )
#set( $creds = "zx5dej31tt:5inkmy78lz")
{
"version": "2018-05-29",
"method": "POST",
"resourcePath": "$indexPath",
"params": {
"headers" : {
"Content-Type" : "application/json",
"Authorization":"Basic $util.base64Encode($creds)"
},
"body": {
"size": #if( $input.limit ) $input.limit #else 100 #end,
"sort": [{
"_geo_distance": {
"location": $util.toJson($input.location),
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
}],
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "${distance}km",
"location" : $util.toJson($input.location)
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment