# Combining must and must not for geo point mapping in ES 5.4

**URL:** <https://discuss.elastic.co/t/combining-must-and-must-not-for-geo-point-mapping-in-es-5-4/103660>\
**Category:** Elasticsearch\
**Created:** [October 12, 2017, 7:25am UTC](https://discuss.elastic.co/t/combining-must-and-must-not-for-geo-point-mapping-in-es-5-4/103660 "2017-10-12T07:25:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![skills-anand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skills-anand/32/57305_2.png) [@skills-anand](https://discuss.elastic.co/u/skills-anand)\
**Post date:** [October 12, 2017, 7:25am UTC](https://discuss.elastic.co/t/combining-must-and-must-not-for-geo-point-mapping-in-es-5-4/103660/1 "2017-10-12T07:25:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 9, 2017, 7:26am UTC](https://discuss.elastic.co/t/combining-must-and-must-not-for-geo-point-mapping-in-es-5-4/103660/2 "2017-11-09T07:26:14Z")

</div>

Closed on November 9, 2017, 7:26am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
