Skip to content

Instantly share code, notes, and snippets.

@lotrak
Created June 2, 2011 13:58
Show Gist options
  • Save lotrak/1004487 to your computer and use it in GitHub Desktop.
Save lotrak/1004487 to your computer and use it in GitHub Desktop.
Trying to get geo searches to work
//Creating new index 'twitter'
curl -XPUT 'http://localhost:9200/twitter/'
//response:
{
"ok":true,
"acknowledged":true
}
//Creating a geo-mapping for pin.location!? for twitter index
curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '{
"pin": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}'
response:
{
"ok":true,
"acknowledged":true
}
//Indexing a geo-aware record to twitter of type tweet
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search",
"pin": {
"location": {
"lat": 7.1383,
"lon": 151.5031
}
}
}'
response:
{
"ok": true,
"_index": "twitter",
"_type": "tweet",
"_id": "1",
"_version": 1
}
//trying to search for tweets located within 200 km of point "7,151"
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "20km",
"location": {
"lat": 7,
"lon": 151
}
}
}
}
}
}'
response:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
//trying to match all tweets with a geo-facet
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
"query" : {
"match_all" : {}
},
"facets" : {
"geo1" : {
"geo_distance" : {
"location" : {
"lat" : 7,
"lon" : 150
},
"ranges" : [
{ "to" : 10 },
{ "from" : 10, "to" : 20 },
{ "from" : 20, "to" : 100 },
{ "from" : 100 }
]
}
}
}
}'
response:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "twitter",
"_type": "tweet",
"_id": "1",
"_score": 1,
"_source": {
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "trying out Elastic Search",
"pin": {
"location": {
"lat": 7.1383,
"lon": 151.5031
}
}
}
}
]
},
"facets": {
"geo1": {
"_type": "geo_distance",
"ranges": [
{
"to": 10,
"min": "Infinity",
"max": "-Infinity",
"total_count": 0,
"total": 0,
"mean": "NaN"
},
{
"from": 10,
"to": 20,
"min": "Infinity",
"max": "-Infinity",
"total_count": 0,
"total": 0,
"mean": "NaN"
},
{
"from": 20,
"to": 100,
"min": "Infinity",
"max": "-Infinity",
"total_count": 0,
"total": 0,
"mean": "NaN"
},
{
"from": 100,
"min": "Infinity",
"max": "-Infinity",
"total_count": 0,
"total": 0,
"mean": "NaN"
}
]
}
}
}
//checking to see if the geopoint is mapped
curl -XGET 'http://localhost:9200/twitter/tweet/_mapping'
response:
{
"tweet": {
"properties": {
"message": {
"type": "string"
},
"pin": {
"dynamic": "true",
"properties": {
"location": {
"dynamic": "true",
"properties": {
"lon": {
"type": "double"
},
"lat": {
"type": "double"
}
}
}
}
},
"location": {
"type": "geo_point"
},
"user": {
"type": "string"
},
"post_date": {
"format": "dateOptionalTime",
"type": "date"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment