Skip to content

Instantly share code, notes, and snippets.

@p3consulting
Created February 12, 2011 15:26
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 p3consulting/823820 to your computer and use it in GitHub Desktop.
Save p3consulting/823820 to your computer and use it in GitHub Desktop.
Test to demonstrate that filter with "exists" doesn't work correctly once an implicit mapping is created.
Depending on if the implicit mapping has been created or not, the result with the "exists" filter condition will be wrong or correct (the total should be 3)"
On one machine, I got empty mapping after _bulk import and the result was correct for the filter "exists" : "geoloc".
On another one (the here bellow results), the implicit mapping was created by _bulk import and the result was incorrect.
In each case if the filtering is done on ""geoloc.lat" instead of "geoloc", the results are correct.
----------- CUT FROM HERE ----------
#!/bin/sh
curl -s -XPOST 'http://192.168.1.2:9200/_bulk' -d '
{"index" : {"_index" : "foo", "_type" : "bar"}}
{"geoloc" : {"lat" : 46.202218, "lon" : 6.146914}}
{"index" : {"_index" : "foo", "_type" : "bar"}}
{"geoloc" : {"lat" : 46.202218, "lon" : 6.146914}}
{"index" : {"_index" : "foo", "_type" : "bar"}}
{"geoloc" : {"lat" : 46.202218, "lon" : 6.146914}}
{"index" : {"_index" : "foo", "_type" : "bar"}}
{"geoloc" : null}
{"index" : {"_index" : "foo", "_type" : "bar"}}
{"geoloc" : null}
'
curl -s -XGET 'http://192.168.1.2:9200/_all/_search?pretty=true' -d '
{
"query" : {
"filtered" : {
"filter" : {
"exists" : {
"field" : "geoloc"
}
},
"query" : {
"matchAll" : {}
}
}
}
}'
curl -s -XGET 'http://192.168.1.2:9200/_all/_search?pretty=true' -d '
{
"query" : {
"filtered" : {
"filter" : {
"exists" : {
"field" : "geoloc.lat"
}
},
"query" : {
"matchAll" : {}
}
}
}
}'
curl -s -XGET http://192.168.1.2:9200/foo/bar/_mapping?pretty=true
exit
----------- CUT TO HERE ----------
This is the output I got here:
{
"took" : 3,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
{
"took" : 5,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "foo",
"_type" : "bar",
"_id" : "A5LkTPUuRsadL0sCcXwm5g",
"_score" : 1.0, "_source" : {"geoloc" : {"lat" : 46.202218, "lon" : 6.146914}}
}, {
"_index" : "foo",
"_type" : "bar",
"_id" : "kWbY8O-cQbS51Ah7ZaJqYQ",
"_score" : 1.0, "_source" : {"geoloc" : {"lat" : 46.202218, "lon" : 6.146914}}
}, {
"_index" : "foo",
"_type" : "bar",
"_id" : "67PADNofTTevO0umPu_o7Q",
"_score" : 1.0, "_source" : {"geoloc" : {"lat" : 46.202218, "lon" : 6.146914}}
} ]
}
}
{
"foo" : {
"bar" : {
"properties" : {
"geoloc" : {
"properties" : {
"lon" : {
"type" : "double"
},
"lat" : {
"type" : "double"
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment