Created
December 6, 2012 19:17
-
-
Save telvis07/4227384 to your computer and use it in GitHub Desktop.
multi-field with geo_point in a nested document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPOST localhost:9200/test -d ' | |
{ | |
"mappings": { | |
"type1": { | |
"properties": { | |
"message": { | |
"index": "analyzed", | |
"type": "string" | |
}, | |
"depart": { | |
"properties": { | |
"city":{"type":"string", "index":"not_analyzed"}, | |
"latlon": { | |
"fields": { | |
"latlon": { | |
"index": "not_analyzed", | |
"type": "string" | |
}, | |
"latlon_geo": { | |
"geohash": false, | |
"geohash_precision": 4, | |
"type": "geo_point", | |
"lat_lon": false | |
} | |
}, | |
"type": "multi_field" | |
} | |
} | |
} | |
} | |
} | |
}, | |
"settings": { | |
"number_of_shards": 1 | |
} | |
}' | |
curl -XPUT 'localhost:9200/test/type1/1' -d ' | |
{ | |
"message" : "something blue", | |
"depart":{"city":"saopaulo", "latlon" : "-23.53,-46.62"} | |
} | |
' | |
curl -XPUT 'localhost:9200/test/type1/2' -d ' | |
{ | |
"message" : "something green", | |
"depart": {"city":"newyork", "latlon" : "40.71,-74.01"} | |
} | |
curl -XPOST 'localhost:9200/_refresh' | |
echo "" | |
echo "Term Facet - shows lat,long" | |
curl -XPOST 'localhost:9200/test/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"match_all":{} | |
}, | |
"facets" : { | |
"geo" : { | |
"terms" : { "field" : "depart.latlon" } | |
} | |
} | |
} | |
' | |
echo "" | |
echo "Geo boundary - works with fully qualified field name" | |
curl -XPOST 'localhost:9200/test/_search?pretty=true' -d ' | |
{ | |
"query": { | |
"filtered" : { | |
"query" : { | |
"match_all" : {} | |
}, | |
"filter" : { | |
"geo_bounding_box" : { | |
"depart.latlon.latlon_geo" : { | |
"top_left" : { | |
"lat" : 55, | |
"lon" : -100 | |
}, | |
"bottom_right" : { | |
"lat" : -25, | |
"lon" : -40 | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
echo "" | |
echo "Geo boundary - fails with \"failed to find geo_point field [depart.latlon_geo]\"" | |
curl -XPOST 'localhost:9200/test/_search?pretty=true' -d ' | |
{ | |
"query": { | |
"filtered" : { | |
"query" : { | |
"match_all" : {} | |
}, | |
"filter" : { | |
"geo_bounding_box" : { | |
"depart.latlon_geo" : { | |
"top_left" : { | |
"lat" : 55, | |
"lon" : -100 | |
}, | |
"bottom_right" : { | |
"lat" : -25, | |
"lon" : -40 | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had a similar mapping, combining a string and a geo_point in a multi_field. ES does not complain when indexing or when creating the mapping but a geo query will fail. The problem is that in a multi_field, all fields must be of the same type, see http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html
I used the field type object instead of multi_field which allows querying as expected. http://www.elasticsearch.org/guide/reference/mapping/object-type.html