Skip to content

Instantly share code, notes, and snippets.

@ofavre
Created May 31, 2011 15:37
Show Gist options
  • Save ofavre/1000701 to your computer and use it in GitHub Desktop.
Save ofavre/1000701 to your computer and use it in GitHub Desktop.
Using boolean queries and fields in ElasticSearch 0.16.1
curl -XDELETE 'http://127.0.0.1:9202/test/bool'
{"ok":true}
curl -XPUT 'http://127.0.0.1:9202/test/bool/_mapping' -d '{"bool":{"properties":{"bool":{"type":"boolean"}}}}'
{"ok":true,"acknowledged":true}
curl -XGET 'http://127.0.0.1:9202/test/bool/_mapping'
{"bool":{"properties":{"bool":{"type":"boolean"}}}}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"yes"}'
{"ok":true,"_index":"test","_type":"bool","_id":"mC0iSbDGRi6ypBBUBOpe0Q","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"T"}'
{"ok":true,"_index":"test","_type":"bool","_id":"EUMdXikfQ0apBcS4tIFPFA","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"1"}'
{"ok":true,"_index":"test","_type":"bool","_id":"IJuxq-_UTa--kb5EYjeHbQ","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"true"}'
{"ok":true,"_index":"test","_type":"bool","_id":"npvAtx-qSy-kV9t3y3uSQA","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"on"}'
{"ok":true,"_index":"test","_type":"bool","_id":"5dEC8q8SRCKUKECxB0SIeg","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"yes"}'
{"ok":true,"_index":"test","_type":"bool","_id":"cZG8pZ5lRD6jXqH-3ctREQ","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"no"}'
{"ok":true,"_index":"test","_type":"bool","_id":"z7KAtdBoTHazJM1JAy5iNQ","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"off"}'
{"ok":true,"_index":"test","_type":"bool","_id":"6TMcTJ7BQAemmWSj7c1rwg","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"false"}'
{"ok":true,"_index":"test","_type":"bool","_id":"BV_ytdCzR6OsM7s15r41-A","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"0"}'
{"ok":true,"_index":"test","_type":"bool","_id":"z0w9oJMBQNifQrj2kstqdQ","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":"F"}'
{"ok":true,"_index":"test","_type":"bool","_id":"-cGGecCqRs6wa_wB2qRUkw","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":false}'
{"ok":true,"_index":"test","_type":"bool","_id":"5CsRCkpYTQeuyUR8JaENgg","_version":1}
curl -XPOST 'http://127.0.0.1:9202/test/bool' -d '{"bool":true}'
{"ok":true,"_index":"test","_type":"bool","_id":"CQEET_FiQTeS07m-ceZE2g","_version":1}
Then I query:
curl -XPOST 'http://127.0.0.1:9202/test/bool/_search?pretty=on' -d '{"query":{"field":{"bool":"T"}}}'
curl -XPOST 'http://127.0.0.1:9202/test/bool/_search?pretty=on' -d '{"query":{"field":{"bool":"F"}}}'
curl -XPOST 'http://127.0.0.1:9202/test/bool/_search?pretty=on' -d '{"query":{"field":{"bool":"T"}}}'
curl -XPOST 'http://127.0.0.1:9202/test/bool/_search?pretty=on' -d '{"query":{"field":{"bool":"F"}}}'
curl -XPOST 'http://127.0.0.1:9202/test/bool/_search?pretty=on' -d '{"query":{"query_string":{"query":"bool:F"}}}'
curl -XPOST 'http://127.0.0.1:9202/test/bool/_search?pretty=on' -d '{"query":{"query_string":{"query":"bool:T"}}}'
curl -XPOST 'http://127.0.0.1:9202/test/bool/_search?pretty=on' -d '{"query":{"term":{"bool":"F"}}}'
curl -XPOST 'http://127.0.0.1:9202/test/bool/_search?pretty=on' -d '{"query":{"term":{"bool":"T"}}}'
All of them give me the same answer:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 9,
"max_score" : 1.3364723,
"hits" : [ {
"_index" : "test",
"_type" : "bool",
"_id" : "mC0iSbDGRi6ypBBUBOpe0Q",
"_score" : 1.3364723, "_source" : {"bool":"yes"}
}, {
"_index" : "test",
"_type" : "bool",
"_id" : "EUMdXikfQ0apBcS4tIFPFA",
"_score" : 1.3364723, "_source" : {"bool":"T"}
}, {
"_index" : "test",
"_type" : "bool",
"_id" : "IJuxq-_UTa--kb5EYjeHbQ",
"_score" : 1.3364723, "_source" : {"bool":"1"}
}, {
"_index" : "test",
"_type" : "bool",
"_id" : "npvAtx-qSy-kV9t3y3uSQA",
"_score" : 1.3364723, "_source" : {"bool":"true"}
}, {
"_index" : "test",
"_type" : "bool",
"_id" : "5dEC8q8SRCKUKECxB0SIeg",
"_score" : 1.3364723, "_source" : {"bool":"on"}
}, {
"_index" : "test",
"_type" : "bool",
"_id" : "cZG8pZ5lRD6jXqH-3ctREQ",
"_score" : 1.3364723, "_source" : {"bool":"yes"}
}, {
"_index" : "test",
"_type" : "bool",
"_id" : "z7KAtdBoTHazJM1JAy5iNQ",
"_score" : 1.3364723, "_source" : {"bool":"no"}
}, {
"_index" : "test",
"_type" : "bool",
"_id" : "-cGGecCqRs6wa_wB2qRUkw",
"_score" : 1.3364723, "_source" : {"bool":"F"}
}, {
"_index" : "test",
"_type" : "bool",
"_id" : "CQEET_FiQTeS07m-ceZE2g",
"_score" : 1.3364723, "_source" : {"bool":true}
} ]
}
}
All queries give me all docs in answer...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment