You can use the should
clause to create and OR filter
Here is a complete example
DELETE discuss-test
PUT discuss-test
{
"mappings": {
"properties": {
"type": {
"type": "keyword"
},
"gender": {
"type": "keyword"
},
"name": {
"type": "keyword"
}
}
}
}
POST discuss-test/_doc
{
"type" : "feline",
"gender" : "male",
"name" : "chuck"
}
POST discuss-test/_doc
{
"type" : "feline",
"gender" : "female",
"name" : "mary"
}
POST discuss-test/_doc
{
"type" : "canis",
"gender" : "male",
"name" : "spot"
}
POST discuss-test/_doc
{
"type" : "canis",
"gender" : "female",
"name" : "mary"
}
Now the query
# This is the equivalent of an OR filter with should
GET discuss-test/_search
{
"query": {
"bool": {
"should": [ <! -- This mean OR, must means AND
{
"term": {
"type": {
"value": "canis"
}
}
},
{
"term": {
"name": {
"value": "mary"
}
}
}
]
}
}
}
and the resulting OR.
{
"took" : 21,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.3862942,
"hits" : [
{
"_index" : "discuss-test",
"_type" : "_doc",
"_id" : "U6tJdXsBm1AJFmUV717P",
"_score" : 1.3862942,
"_source" : {
"type" : "canis",
"gender" : "female",
"name" : "mary"
}
},
{
"_index" : "discuss-test",
"_type" : "_doc",
"_id" : "UatJdXsBm1AJFmUV716l",
"_score" : 0.6931471,
"_source" : {
"type" : "feline",
"gender" : "female",
"name" : "mary"
}
},
{
"_index" : "discuss-test",
"_type" : "_doc",
"_id" : "UqtJdXsBm1AJFmUV7162",
"_score" : 0.6931471,
"_source" : {
"type" : "canis",
"gender" : "male",
"name" : "spot"
}
}
]
}
}