Skip to content

Instantly share code, notes, and snippets.

@maruf89
Last active August 29, 2015 14:17
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 maruf89/7c1cb805511b48ac7720 to your computer and use it in GitHub Desktop.
Save maruf89/7c1cb805511b48ac7720 to your computer and use it in GitHub Desktop.
Bounding box query not working
echo 'Loading test_index mapping'
curl -XPUT localhost:9200/test_index -d '{
"mappings":{
"user":{
"_id":{
"path":"userID"
},
"_routing":{
"path":"userID"
},
"properties":{
"aboutContact":{
"type":"string"
},
"acceptMessage":{
"type":"boolean"
},
"acceptTandem":{
"type":"boolean"
},
"address":{
"type":"string",
"index":"no"
},
"attending":{
"type":"nested",
"properties":{
"events":{
"type":"integer"
},
"eventsWaitList":{
"type":"integer"
}
}
},
"availabilityText":{
"type":"string",
"index":"no"
},
"birthday":{
"type":"date",
"format":"date"
},
"city":{
"type":"string"
},
"coords":{
"type":"geo_point"
},
"country":{
"type":"string"
},
"email":{
"type":"string",
"index":"not_analyzed"
},
"firstName":{
"type":"string",
"index":"not_analyzed"
},
"following":{
"type":"integer",
"index":"no"
},
"follows":{
"type":"integer",
"index":"no"
},
"id":{
"type":"string"
},
"joinDate":{
"type":"date",
"format":"basic_date_time"
},
"lastName":{
"type":"string",
"index":"not_analyzed"
},
"locale":{
"type":"string"
},
"locations":{
"type":"integer",
"index":"no"
},
"personal":{
"type":"string",
"index":"no"
},
"postal":{
"type":"string"
},
"postalCode":{
"type":"string",
"index":"no"
},
"state":{
"type":"string"
},
"userGroup":{
"type":"string"
},
"userID":{
"type":"integer"
}
}
}
}
}'
echo 'Indexing user'
curl -XPUT localhost:9200/test_index/user/149 -d '{
"firstName":"bob",
"lastName":"Jones",
"locale":"en_US",
"email":"bob@cherrypicking.com",
"details":{
"birthday":"1989-02-20",
"gender":"MALE"
},
"joinDate":"20150308T082423.559+02:00",
"userGroup":"2",
"userID":149,
"country":"DE",
"address":null,
"city":"Berlin",
"name":null,
"state":"Berlin",
"postal":null,
"coords":{
"lat":52.52000659999999,
"lon":13.404953999999975
}
}'
echo 'The bounding box query that returns no results'
curl -XGET http://localhost:9200/test_index/user/_search -d '{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"geo_bounding_box":{
"coords":{
"top_left":{
"lat":50,
"lon":10
},
"bottom_right":{
"lat":55,
"lon":15
}
}
}
}
}
}
}'
echo 'Similar geo distance query that does work'
curl -XGET http://localhost:9200/test_index/user/_search -d '{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"geo_distance":{
"distance": "1km",
"coords":{
"lat":52.52000659999999,
"lon":13.404953999999975
}
}
}
}
},
"fields": ["userID"]
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment