I'm trying to get some geodata out of ES via the following snippet:
result = es.search(
index="loc",
body={
{
"filtered" : {
"query" : {
"field" : { "text" : "restaurant" }
},
"filter" : {
"geo_distance" : {
"distance" : "12km",
"location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}
)
The query however doesn't succeed due to the following error:
"lon" : -70
TypeError: unhashable type: 'dict'
The location field is correctly mapped to the geo_point type and the query is taken from the official examples. Is there something wrong with the way I wrote the query?
You are nesting a dict inside a set. Remove outer curly braces to resolve the issue. The error stems from the fact that sets, dicts can't contain unhashable collections like e.g. dict (thanks @Matthias).
body=
{
"filtered" : {
"query" : {
"field" : { "text" : "restaurant" }
},
"filter" : {
"geo_distance" : {
"distance" : "12km",
"location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With