Skip to content

Instantly share code, notes, and snippets.

@missinglink
Created January 5, 2015 14:06
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 missinglink/4bf3e262fbd0a89d3f5e to your computer and use it in GitHub Desktop.
Save missinglink/4bf3e262fbd0a89d3f5e to your computer and use it in GitHub Desktop.
Pre-indexed shapes using geo_shape filter (not working)
#!/bin/bash
################################################
# Pre-indexed shapes using geo_shape filter
################################################
ES='localhost:9200';
# Remove old data
curl -XDELETE "$ES/shapes?pretty=true";
curl -XDELETE "$ES/business?pretty=true";
# Create shapes index, with mapping
curl -XPOST "$ES/shapes?pretty=true" -d '
{
"mappings": {
"municipalities": {
"properties": {
"poly": {
"type": "geo_shape",
"tree": "quadtree",
"tree_levels": 26
}
}
}
}
}';
# Add a municipality to the shapes index
curl -XPOST "$ES/shapes/municipalities/1?pretty=true" -d '
{
"poly": {
"type":"Polygon",
"coordinates": [
[[-78.52364,38.022739],[-78.52335,38.023536],[-78.52313,38.02634],[-78.52005,38.02604],[-78.52026,38.028301],[-78.519832,38.028644],[-78.520179,38.029781],[-78.51833,38.02984],[-78.51829,38.028558],[-78.51431,38.02876],[-78.51101,38.03083],[-78.50961,38.03216],[-78.5088,38.03227],[-78.50796,38.03197],[-78.50711,38.032108],[-78.50458,38.03202],[-78.50184,38.03213],[-78.49779,38.033255],[-78.49853,38.033448],[-78.50025,38.034451],[-78.50166,38.036136],[-78.50346,38.036746],[-78.50125,38.04041],[-78.50204,38.041226],[-78.5036,38.042217],[-78.50422,38.04284],[-78.50498,38.042581],[-78.50577,38.04128],[-78.50523,38.041038],[-78.50593,38.040138],[-78.50614,38.03944],[-78.50683,38.039338],[-78.5081,38.035831],[-78.51333,38.037137],[-78.51553,38.036738],[-78.51689,38.039879],[-78.51638,38.040286],[-78.51737,38.04119],[-78.51607,38.04349],[-78.51396,38.04418],[-78.51463,38.044838],[-78.51141,38.04379],[-78.50678,38.04496],[-78.50593,38.04552],[-78.50484,38.047275],[-78.510297,38.051308],[-78.50753,38.05642],[-78.50134,38.057685],[-78.50088,38.05844],[-78.50231,38.06053],[-78.49885,38.06281],[-78.49553,38.064837],[-78.49503,38.065337],[-78.49264,38.06363],[-78.49158,38.06189],[-78.485154,38.069027],[-78.48253,38.067637],[-78.48113,38.066738],[-78.48094,38.06563],[-78.48031,38.065794],[-78.4789,38.065647],[-78.47719,38.064752],[-78.47598,38.06669],[-78.47453,38.06771],[-78.47494,38.068683],[-78.472985,38.07013],[-78.4714,38.070591],[-78.47073,38.06974],[-78.47234,38.067515],[-78.46853,38.068131],[-78.46843,38.067631],[-78.46689,38.06783],[-78.46547,38.065777],[-78.46433,38.064637],[-78.46784,38.05913],[-78.46963,38.055838],[-78.47223,38.052638],[-78.47143,38.050438],[-78.47213,38.049738],[-78.47233,38.049037],[-78.47082,38.048918],[-78.46993,38.04704],[-78.46612,38.045769],[-78.46543,38.047138],[-78.46533,38.048138],[-78.46438,38.04875],[-78.46403,38.049538],[-78.46145,38.04946],[-78.45733,38.049538],[-78.45717,38.05031],[-78.45872,38.05094],[-78.456921,38.055035],[-78.45658,38.05555],[-78.45471,38.054729],[-78.44905,38.05873],[-78.44776,38.057182],[-78.44749,38.0558],[-78.44759,38.054215],[-78.44717,38.051105],[-78.446311,38.04942],[-78.44729,38.04615],[-78.44909,38.045248],[-78.45182,38.045788],[-78.45392,38.045803],[-78.45464,38.045361],[-78.45484,38.043939],[-78.45411,38.042394],[-78.45419,38.039615],[-78.45499,38.037605],[-78.45619,38.03632],[-78.45877,38.034354],[-78.45994,38.033212],[-78.46032,38.03224],[-78.46036,38.03051],[-78.46101,38.02922],[-78.46077,38.02776],[-78.45938,38.02741],[-78.45828,38.02793],[-78.45762,38.028743],[-78.45611,38.029742],[-78.45467,38.029863],[-78.45323,38.028985],[-78.45246,38.02802],[-78.45264,38.02645],[-78.4547,38.022101],[-78.45665,38.021147],[-78.45933,38.022439],[-78.46163,38.022639],[-78.46208,38.02249],[-78.46356,38.020533],[-78.46693,38.01836],[-78.46923,38.014739],[-78.46843,38.01404],[-78.46973,38.01144],[-78.474634,38.01304],[-78.4751,38.013518],[-78.47473,38.01424],[-78.47563,38.014739],[-78.47804,38.01412],[-78.47942,38.013385],[-78.48026,38.01333],[-78.4815,38.011956],[-78.48316,38.011956],[-78.4833,38.014471],[-78.48453,38.0157],[-78.48666,38.016138],[-78.48727,38.016555],[-78.48895,38.01667],[-78.49033,38.017257],[-78.491351,38.016922],[-78.49197,38.01624],[-78.49351,38.01502],[-78.49486,38.01443],[-78.495661,38.014409],[-78.498837,38.012904],[-78.49988,38.01286],[-78.50079,38.01214],[-78.50172,38.01105],[-78.5033,38.0102],[-78.50443,38.010118],[-78.50724,38.01086],[-78.50828,38.01128],[-78.50929,38.011082],[-78.510179,38.009923],[-78.51156,38.009589],[-78.51285,38.0096],[-78.51475,38.00994],[-78.51738,38.010245],[-78.51915,38.01083],[-78.51882,38.011865],[-78.51875,38.013211],[-78.51911,38.0146],[-78.51904,38.015308],[-78.51954,38.017252],[-78.52046,38.01773],[-78.52037,38.01835],[-78.5213,38.018884],[-78.5221,38.018423],[-78.52343,38.019539],[-78.52364,38.022739]]
]
}
}';
# Create business index, with mapping
curl -XPOST "$ES/business?pretty=true" -d '
{
"mappings": {
"place": {
"properties": {
"name": {
"type": "string"
},
"location": {
"type": "geo_point",
"lat_lon": "true"
}
}
}
}
}';
# Add a business document to the business index
curl -XPOST "$ES/business/place/1?pretty=true" -d '
{
"name": "JON DOE",
"location": {
"lat": "1",
"lon": "1"
}
}';
# Refresh indices
curl -XPOST "$ES/business/_refresh?pretty=true";
curl -XPOST "$ES/shapes/_refresh?pretty=true";
# Run our search
curl -XPOST "$ES/business/place/_search?pretty=true" -d '
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_shape": {
"location": {
"indexed_shape": {
"id": "1",
"type": "municipalities",
"index": "shapes",
"path": "poly"
}
}
}
}
}
}
}';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment