Skip to content

Instantly share code, notes, and snippets.

@oakstream
Created February 25, 2013 20:45
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 oakstream/5033131 to your computer and use it in GitHub Desktop.
Save oakstream/5033131 to your computer and use it in GitHub Desktop.
ElasticSearch Test Case , Query is not selecting all 3 indexes during spatial query. (Also first query is not returning any records...this might be user error)??
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Costa de Xurius", "dem": "1434", "geonameid": "3038814", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.5 , 1.48333", "cc2": null, "fcode": "SLP", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Costa de Xurius", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Costa de Xurius", "dem": "1434", "geonameid": "3038814", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.5 , 1.48333", "cc2": null, "fcode": "SLP", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Costa de Xurius", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Costa de Xurius", "dem": "1434", "geonameid": "3038814", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.5 , 1.48333", "cc2": null, "fcode": "SLP", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Costa de Xurius", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "H", "admin1": "04", "elevation": null, "name": "Font de la Xona", "dem": "1976", "geonameid": "3038815", "country": "AD", "moddate": "2010-01-11", "lon": 1.44986, "location": "42.55003 , 1.44986", "cc2": null, "fcode": "SPNG", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55003, "asciiname": "Font de la Xona", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "H", "admin1": "04", "elevation": null, "name": "Font de la Xona", "dem": "1976", "geonameid": "3038815", "country": "AD", "moddate": "2010-01-11", "lon": 1.44986, "location": "42.55003 , 1.44986", "cc2": null, "fcode": "SPNG", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55003, "asciiname": "Font de la Xona", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "H", "admin1": "04", "elevation": null, "name": "Font de la Xona", "dem": "1976", "geonameid": "3038815", "country": "AD", "moddate": "2010-01-11", "lon": 1.44986, "location": "42.55003 , 1.44986", "cc2": null, "fcode": "SPNG", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55003, "asciiname": "Font de la Xona", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "P", "admin1": "04", "elevation": null, "name": "Xixerella", "dem": "1417", "geonameid": "3038816", "country": "AD", "moddate": "2009-04-24", "lon": 1.48736, "location": "42.55327 , 1.48736", "cc2": null, "fcode": "PPL", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55327, "asciiname": "Xixerella", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "P", "admin1": "04", "elevation": null, "name": "Xixerella", "dem": "1417", "geonameid": "3038816", "country": "AD", "moddate": "2009-04-24", "lon": 1.48736, "location": "42.55327 , 1.48736", "cc2": null, "fcode": "PPL", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55327, "asciiname": "Xixerella", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "P", "admin1": "04", "elevation": null, "name": "Xixerella", "dem": "1417", "geonameid": "3038816", "country": "AD", "moddate": "2009-04-24", "lon": 1.48736, "location": "42.55327 , 1.48736", "cc2": null, "fcode": "PPL", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55327, "asciiname": "Xixerella", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "A", "admin1": "00", "elevation": null, "name": "Xixerella", "dem": "1520", "geonameid": "3038817", "country": "AD", "moddate": "2012-04-13", "lon": 1.48764, "location": "42.55294 , 1.48764", "cc2": null, "fcode": "ADMD", "alternatenames": "Xixerella", "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55294, "asciiname": "Xixerella", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "A", "admin1": "00", "elevation": null, "name": "Xixerella", "dem": "1520", "geonameid": "3038817", "country": "AD", "moddate": "2012-04-13", "lon": 1.48764, "location": "42.55294 , 1.48764", "cc2": null, "fcode": "ADMD", "alternatenames": "Xixerella", "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55294, "asciiname": "Xixerella", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "A", "admin1": "00", "elevation": null, "name": "Xixerella", "dem": "1520", "geonameid": "3038817", "country": "AD", "moddate": "2012-04-13", "lon": 1.48764, "location": "42.55294 , 1.48764", "cc2": null, "fcode": "ADMD", "alternatenames": "Xixerella", "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.55294, "asciiname": "Xixerella", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Riu Xic", "dem": "2121", "geonameid": "3038818", "country": "AD", "moddate": "1993-12-23", "lon": 1.68333, "location": "42.56667 , 1.68333", "cc2": null, "fcode": "STM", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Riu Xic", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Riu Xic", "dem": "2121", "geonameid": "3038818", "country": "AD", "moddate": "1993-12-23", "lon": 1.68333, "location": "42.56667 , 1.68333", "cc2": null, "fcode": "STM", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Riu Xic", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Riu Xic", "dem": "2121", "geonameid": "3038818", "country": "AD", "moddate": "1993-12-23", "lon": 1.68333, "location": "42.56667 , 1.68333", "cc2": null, "fcode": "STM", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Riu Xic", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "R", "admin1": "00", "elevation": null, "name": "Pas del Xic", "dem": "1961", "geonameid": "3038819", "country": "AD", "moddate": "1993-12-23", "lon": 1.58333, "location": "42.5 , 1.58333", "cc2": null, "fcode": "TRL", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Pas del Xic", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "R", "admin1": "00", "elevation": null, "name": "Pas del Xic", "dem": "1961", "geonameid": "3038819", "country": "AD", "moddate": "1993-12-23", "lon": 1.58333, "location": "42.5 , 1.58333", "cc2": null, "fcode": "TRL", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Pas del Xic", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "R", "admin1": "00", "elevation": null, "name": "Pas del Xic", "dem": "1961", "geonameid": "3038819", "country": "AD", "moddate": "1993-12-23", "lon": 1.58333, "location": "42.5 , 1.58333", "cc2": null, "fcode": "TRL", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Pas del Xic", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Roc del Xeig", "dem": "1740", "geonameid": "3038820", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.56667 , 1.48333", "cc2": null, "fcode": "RK", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Roc del Xeig", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Roc del Xeig", "dem": "1740", "geonameid": "3038820", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.56667 , 1.48333", "cc2": null, "fcode": "RK", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Roc del Xeig", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Roc del Xeig", "dem": "1740", "geonameid": "3038820", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.56667 , 1.48333", "cc2": null, "fcode": "RK", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Roc del Xeig", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Collada del Xeig", "dem": "1740", "geonameid": "3038821", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.56667 , 1.48333", "cc2": null, "fcode": "PK", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Collada del Xeig", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Collada del Xeig", "dem": "1740", "geonameid": "3038821", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.56667 , 1.48333", "cc2": null, "fcode": "PK", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Collada del Xeig", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "T", "admin1": "00", "elevation": null, "name": "Collada del Xeig", "dem": "1740", "geonameid": "3038821", "country": "AD", "moddate": "1993-12-23", "lon": 1.48333, "location": "42.56667 , 1.48333", "cc2": null, "fcode": "PK", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.56667, "asciiname": "Collada del Xeig", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Fonts Vives", "dem": "1684", "geonameid": "3038822", "country": "AD", "moddate": "1993-12-23", "lon": 1.56667, "location": "42.5 , 1.56667", "cc2": null, "fcode": "SPNG", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Fonts Vives", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Fonts Vives", "dem": "1684", "geonameid": "3038822", "country": "AD", "moddate": "1993-12-23", "lon": 1.56667, "location": "42.5 , 1.56667", "cc2": null, "fcode": "SPNG", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Fonts Vives", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Fonts Vives", "dem": "1684", "geonameid": "3038822", "country": "AD", "moddate": "1993-12-23", "lon": 1.56667, "location": "42.5 , 1.56667", "cc2": null, "fcode": "SPNG", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": "Europe/Andorra", "lat": 42.5, "asciiname": "Fonts Vives", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "North Sahul Passage", "dem": "-9999", "geonameid": "8435390", "country": null, "moddate": "2012-12-07", "lon": 127.0651, "location": "-10.15542 , 127.0651", "cc2": null, "fcode": "CHNM", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": null, "lat": -10.15542, "asciiname": "North Sahul Passage", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "North Sahul Passage", "dem": "-9999", "geonameid": "8435390", "country": null, "moddate": "2012-12-07", "lon": 127.0651, "location": "-10.15542 , 127.0651", "cc2": null, "fcode": "CHNM", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": null, "lat": -10.15542, "asciiname": "North Sahul Passage", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "North Sahul Passage", "dem": "-9999", "geonameid": "8435390", "country": null, "moddate": "2012-12-07", "lon": 127.0651, "location": "-10.15542 , 127.0651", "cc2": null, "fcode": "CHNM", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": null, "lat": -10.15542, "asciiname": "North Sahul Passage", "population": "0"}
{ "index" : {"_index" : "geoindex10", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Star Reefs", "dem": "-9999", "geonameid": "8435588", "country": null, "moddate": "2012-12-07", "lon": 149.83008, "location": "-8.45896 , 149.83008", "cc2": null, "fcode": "RF", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": null, "lat": -8.45896, "asciiname": "Star Reefs", "population": "0"}
{ "index" : {"_index" : "geoindex11", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Star Reefs", "dem": "-9999", "geonameid": "8435588", "country": null, "moddate": "2012-12-07", "lon": 149.83008, "location": "-8.45896 , 149.83008", "cc2": null, "fcode": "RF", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": null, "lat": -8.45896, "asciiname": "Star Reefs", "population": "0"}
{ "index" : {"_index" : "geoindex12", "_type" : "geo"} }
{"fclass": "H", "admin1": "00", "elevation": null, "name": "Star Reefs", "dem": "-9999", "geonameid": "8435588", "country": null, "moddate": "2012-12-07", "lon": 149.83008, "location": "-8.45896 , 149.83008", "cc2": null, "fcode": "RF", "alternatenames": null, "admin3": null, "admin2": null, "admin4": null, "timezone": null, "lat": -8.45896, "asciiname": "Star Reefs", "population": "0"}
curl -XDELETE 'http://localhost:9200/geoindex10'
curl -XDELETE 'http://localhost:9200/geoindex11'
curl -XDELETE 'http://localhost:9200/geoindex12'
curl -XPUT 'http://localhost:9200/geoindex10' -d '
index :
number_of_shards : 1
number_of_replicas : 1
refresh_interval : 1s
'
curl -XPUT 'http://localhost:9200/geoindex10/geo/_mapping' -d '
{
"geo" : {
"properties": {
fclass: { "type": "string" },
admin1: { "type": "string" },
elevation: { "type": "integer" },
name: { "type": "string" },
dem: { "type": "string" },
geonameid: { "type": "integer" },
country: { "type": "string" },
moddate: { "format": "yyyy-MM-DD", "type": "date" },
lon: { "type": "float" },
location: { "type": "geo_point" },
cc2: { "type": "string" },
fcode: { "type": "string", "store": "yes" },
alternatenames: { "type": "string" },
admin3: { "type": "string" },
admin2: { "type": "string" },
admin4: { "type": "string" },
timezone: { "type": "string" },
lat: { "type": "float" },
asciiname: { "type": "string" },
population: { "type": "integer" }
}
}
}
'
curl -XPUT 'http://localhost:9200/geoindex11' -d '
index :
number_of_shards : 1
number_of_replicas : 1
refresh_interval : 1s
'
curl -XPUT 'http://localhost:9200/geoindex11/geo/_mapping' -d '
{
"geo" : {
"properties": {
fclass: { "type": "string" },
admin1: { "type": "string" },
elevation: { "type": "integer" },
name: { "type": "string" },
dem: { "type": "string" },
geonameid: { "type": "integer" },
country: { "type": "string" },
moddate: { "format": "yyyy-MM-DD", "type": "date" },
lon: { "type": "float" },
location: { "type": "geo_point" },
cc2: { "type": "string" },
fcode: { "type": "string", "store": "yes" },
alternatenames: { "type": "string" },
admin3: { "type": "string" },
admin2: { "type": "string" },
admin4: { "type": "string" },
timezone: { "type": "string" },
lat: { "type": "float" },
asciiname: { "type": "string" },
population: { "type": "integer" }
}
}
}
'
curl -XPUT 'http://localhost:9200/geoindex12' -d '
index :
number_of_shards : 1
number_of_replicas : 1
refresh_interval : 1s
'
curl -XPUT 'http://localhost:9200/geoindex12/geo/_mapping' -d '
{
"geo" : {
"properties": {
fclass: { "type": "string" },
admin1: { "type": "string" },
elevation: { "type": "integer" },
name: { "type": "string" },
dem: { "type": "string" },
geonameid: { "type": "integer" },
country: { "type": "string" },
moddate: { "format": "yyyy-MM-DD", "type": "date" },
lon: { "type": "float" },
location: { "type": "geo_point" },
cc2: { "type": "string" },
fcode: { "type": "string", "store": "yes" },
alternatenames: { "type": "string" },
admin3: { "type": "string" },
admin2: { "type": "string" },
admin4: { "type": "string" },
timezone: { "type": "string" },
lat: { "type": "float" },
asciiname: { "type": "string" },
population: { "type": "integer" }
}
}
}
'
curl -s -XPOST localhost:9200/_bulk/ --data-binary @new.json
#Pause a few seconds
sleep 3
#Searches multiple indexes
# This doesn't seem to bring me any records although country is in the Data with AD
# Previously I was able to get it to work at some point but this test case doesn't ??
curl -XGET 'http://localhost:9200/geoindex10,geoindex11,geoindex12/geo/_search' -d '{
"query" : {
"term" : { "country" : "AD" }
}
}
'
#Search within distance
#This only brings back records for geoindex10 (the first index created) most of time
# In latest test it also brought back one record in geoindex11. The data in these
#indexes is all the same so it should bring back the same results for each index
# However if you take geoindex10 out then it WILL return all records for geoindex11 and 1 record for geoindex12
# I've also tried using an alias called geonames for all 3 indexes but same similar behavior
curl -XGET 'http://localhost:9200/geoindex11,geoindex12/geo/_search?pretty=true' -d '
{
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "1000km",
"location" : {
"lat" : 42.5,
"lon" : 1.4833
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment