Hi,
We are using elastisearch for sports events which requires geoblocking due
to rights. Below is final filter from Java API. I removed parts which are
not needed for this issue.
{
"filter" : {
"and" : {
"filters" : [ {
"query" : {
"bool" : {
"should" : [ {
"bool" : {
"must" : [ {
"term" : {
"blockByDefault" : true
}
}, {
"term" : {
"allowedCountryCodes" : "it"
}
} ]
}
}, {
"bool" : {
"must" : {
"term" : {
"blockByDefault" : false
}
},
"must_not" : {
"term" : {
"blockedCountryCodes" : "it"
}
}
}
} ],
"minimum_number_should_match" : 1
}
}
} ]
}
}
}
When blockByDefault is set to true, then it should behave as whitelist (allow
only countries defined in allowedCountryCodes), otherwise blacklist (block
only countries defined in blockedCountryCodes).
Here is the mapping:
{
"event" : {
"properties" : {
"blockByDefault" : {"type" : "boolean", "store" : "yes", "index" :
"not_analyzed"},
"allowedCountryCodes" : {"type" : "string", "store" : "yes", "index"
: "not_analyzed"},
"blockedCountryCodes" : {"type" : "string", "store" : "yes", "index"
: "not_analyzed"}
}
}
}
Here is test data:
{"blockByDefault" : true, "allowedCountryCodes" : ["gb", "sk"], "blockedCountryCodes"
: ["it", "sk"]}
{"blockByDefault" : true, "allowedCountryCodes" : ["gb", "sk"], "blockedCountryCodes"
: ["it", "sk"]}
{"blockByDefault" : false, "allowedCountryCodes" : ["gb", "sk"], "blockedCountryCodes"
: ["it", "sk"]}
{"blockByDefault" : false, "allowedCountryCodes" : ["gb", "sk"], "blockedCountryCodes"
: ["it", "sk"]}
{"blockByDefault" : false, "allowedCountryCodes" : ["gb", "sk"], "blockedCountryCodes"
: ["it", "sk"]}
Expected number of results for the following countries are as follows:
- gb 5
- de 3
- sk 2
- it 0 - this is problem, as it returns 3 results (the ones with
blockByDefault set to false) instead of 0.
Everything works except the last case, when all events should be blocked
from Italy, but it doesn't work here.
I've tried to rewrite it in other ways, but still the same results. I've
also tried to filter the events where there is Italy in blockedCountryCodes
and it worked, but then when I added blockByDefault "switch", it returned
bad results. What am I doing wrong?
Thanks
Jan