Skip to content

Instantly share code, notes, and snippets.

@hxuanji
Created September 2, 2014 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hxuanji/e5acd9a5174ea10c08b8 to your computer and use it in GitHub Desktop.
Save hxuanji/e5acd9a5174ea10c08b8 to your computer and use it in GitHub Desktop.
name boost geo sorting
echo -e "delete index..."
curl -XDELETE "http://localhost:5028/test"
echo -e "\ncreate index..."
curl -XPUT "http://localhost:5028/test" -d '
{
"settings": {
"index": {
"number_of_shards": 5,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
},
"filter": {
}
}
}
},
"mappings": {
"main": {
"properties": {
"loc": { "type": "geo_point"},
"name": { "type": "string", "index": "analyzed", "analyzer": "standard", "include_in_all": true}
}
}
}
}
'
echo -e "\npush doc..."
curl -XPOST "http://localhost:5028/test/main" -d '{"loc":{"lat":10, "lon":10}, "name": "abc"}'
curl -XPOST "http://localhost:5028/test/main" -d '{"loc":{"lat":10, "lon":11}, "name": "rtg"}'
curl -XPOST "http://localhost:5028/test/main" -d '{"loc":{"lat":10, "lon":12}, "name": "ivan"}'
echo -e "\nsearch..."
sleep 2
curl -XPOST "http://localhost:5028/test/main/_search" -d '
{ "query" : {
"bool" : {
"must": [
{"filtered" : {
"filter" : {
"geo_distance" : {
"distance" : "2000km",
"loc" : {
"lat" : 10,
"lon" : 10
}
}
}
}}],
"should" : [ { "term" : { "name": { "value" : "ivan", "boost" : 10 }}}]}},
"sort" : [
"_score",
{
"_geo_distance" : {
"loc" : [10, 10],
"order" : "asc",
"unit" : "km",
"mode" : "min",
"distance_type" : "sloppy_arc"
}
}
]
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment