-
Notifications
You must be signed in to change notification settings - Fork 9
/
multi_geo_search.sh
executable file
·64 lines (62 loc) · 1.48 KB
/
multi_geo_search.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
#
# Example of sorting on multiple geo_points
#
curl -XDELETE 'localhost:9200/geotest'
echo
curl -XPOST 'localhost:9200/geotest' -d'{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
},
"mappings": {
"doc": {
"properties": {
"name": {
"type": "string"
},
"geo_points": {
"properties": {
"point": {
"type": "geo_point"
}
}
}
}
}
}
}
'
echo
curl -XPOST 'localhost:9200/geotest/doc/1' -d '{
"name": "foo",
"geo_points": [ {
"point": "59.957,30.303"
}, {
"point": "0.004,0.004"
}, {
"point": "59.948,30.276"
}, {
"point": "59.944,30.272"
}]
}'
echo
curl -XPOST 'localhost:9200/geotest/_refresh'
echo
curl 'localhost:9200/geotest/doc/_search?pretty' -d'{
"query": {
"match_all": {}
},
"sort": {
"_script": {
"script": "import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.unit.DistanceUnit; Collections.min((GeoDistance.ARC.calculate($.lat, $.lon, plat, plon, DistanceUnit.MILES) in doc[\"geo_points.point\"].values))",
"type": "number",
"params": {
"plat": 55.0,
"plon": 30.0
},
"order": "asc"
}
}
}
'