I would like to write an ES query to get the unique users which are presented in geo shape but not in sub geo shape
I have 2 unique users which are present under a geo shape of a city . I have a sub geo shape (some part of that city) where one of the unique user is already presented in this sub geo shape also. My ES query is as follows.
If i use main geo shape to get users list
GET logs/log/_search
{
"query": {
"bool": {
"filter": [
{
"bool": {
"must":[
{
"geo_polygon": {
"coordinates": {
"points": [
[5.3998320648516,43.274624452018],[5.3939307975682,43.267881487058]....
]
}
}
}
]
}
}]
}
}
}
I got 3 results which is fine
"hits": {
"total": 3,
"max_score": 0,
"hits": [
{
"userid": "ANAND"
},
{
"userid": "CEDRIC"
},
{
"userid": "CEDRIC"
}
]
}
If i do a query for sub geo shape
GET logs/log/_search
{
"query": {
"bool": {
"filter": [
{
"bool": {
"must":[
{
"geo_polygon": {
"coordinates": {
"points": [
[5.3925477285553,43.243294948788],[5.3915112689392,43.235988827285]....
]
}
}
}
]
}
}]
}
}
}
I got 1 results which is fine
"hits": {
"total": 1,
"max_score": 0,
"hits": [
{
"userid": "CEDRIC"
}
]
}
If i want to get unique users which are in main geo shape but not in sub geo shape
GET logs/log/_search
{
"query": {
"bool": {
"must": [
{
"geo_polygon": {
"coordinates": {
"points": [
[5.3998320648516,43.274624452018],[5.3939307975682,43.267881487058]....
]
}
}
}
],
"filter": {
"bool": {
"must_not":
{
"geo_polygon": {
"coordinates": {
"points": [
[5.3925477285553,43.243294948788],[5.3915112689392,43.235988827285]...
]
}
}
}
}
}
}
}
}
result seems not correct
"hits": {
"total": 1,
"max_score": 0,
"hits": [
{
"userid": "CEDRIC"
}
]
}
As per my point i should get 0 results but here still am getting 1 user as CEDRIC is already presented in main geoshape. Any suggestions would be helpful. Thanks in advance