Created
March 25, 2014 13:52
-
-
Save tstibbs/9762265 to your computer and use it in GitHub Desktop.
Elasticsearch geo field causing query parser failure for index which doesn't have that field
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 -XPUT localhost:9200/test1 -d '{ | |
"settings": { | |
"number_of_shards": 1, | |
"number_of_replicas": 0 | |
}, | |
"mappings": { | |
"type1": { | |
"properties": { | |
"geofield": { | |
"type": "geo_point" | |
} | |
} | |
} | |
} | |
}' | |
curl -XPUT localhost:9200/test2 -d '{ | |
"settings": { | |
"number_of_shards": 1, | |
"number_of_replicas": 0 | |
}, | |
"mappings": { | |
"type1": { | |
"properties": { | |
"another_field": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
}' | |
curl -XPOST 'http://localhost:9200/_aliases' -d ' | |
{ | |
"actions": [ | |
{ | |
"add": { | |
"index": "test1", | |
"alias": "alias1" | |
} | |
}, | |
{ | |
"add": { | |
"index": "test2", | |
"alias": "alias1" | |
} | |
} | |
] | |
}' | |
curl -XPUT 'http://localhost:9200/test1/type1/1' -d ' | |
{ | |
"geofield" : [0, 50] | |
}' | |
curl -XPUT 'http://localhost:9200/test2/type1/1' -d ' | |
{ | |
"another_field" : "blah" | |
}' | |
// the following queries return one doc each (which is correct) but the first also returns some errors | |
curl -XPOST 'http://localhost:9200/alias1/_search' -d ' | |
{ | |
"query": { | |
"constant_score": { | |
"filter": { | |
"geo_bounding_box": { | |
"geofield": { | |
"top_left": [ | |
-179, | |
89 | |
], | |
"bottom_right": [ | |
179, | |
-89 | |
] | |
} | |
} | |
} | |
} | |
} | |
}' | |
// returns the following: | |
{ | |
"took" : 2, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 2, | |
"successful" : 1, | |
"failed" : 1, | |
"failures" : [ { | |
"index" : "test2", | |
"shard" : 0, | |
"status" : 400, | |
"reason" : "SearchParseException[[test2][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n\t\"query\": {\n\t\t\"constant_score\": {\n\t\t\t\"filter\": {\n\t\t\t\t\"geo_bounding_box\": {\n\t\t\t\t\t\"geofield\": {\n\t\t\t\t\t\t\"top_left\": [\n\t\t\t\t\t\t\t-179,\n\t\t\t\t\t\t\t89\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"bottom_right\": [\n\t\t\t\t\t\t\t179,\n\t\t\t\t\t\t\t-89\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}]]]; | |
nested: QueryParsingException[[test2] failed to find geo_point field [geofield]]; " | |
} ] | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 1.0, | |
"hits" : [ { | |
"_index" : "test1", | |
"_type" : "type1", | |
"_id" : "1", | |
"_score" : 1.0, "_source" : {"geofield":[0,50]} | |
} ] | |
} | |
} | |
curl -XPOST 'http://localhost:9200/alias1/_search' -d ' | |
{ | |
"query": { | |
"match": { | |
"another_field": "blah" | |
} | |
} | |
}' | |
//returns the following: | |
{ | |
"took" : 3, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 2, | |
"successful" : 2, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.30685282, | |
"hits" : [ { | |
"_index" : "test2", | |
"_type" : "type1", | |
"_id" : "1", | |
"_score" : 0.30685282, "_source" : {"another_field":"blah"} | |
} ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment