# What is the difference between CONTAINS and INTERSECTS?

**URL:** <https://discuss.elastic.co/t/what-is-the-difference-between-contains-and-intersects/226791>\
**Category:** Elasticsearch\
**Created:** [April 6, 2020, 10:26pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-contains-and-intersects/226791 "2020-04-06T22:26:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hariseldon3141](https://avatars.discourse-cdn.com/v4/letter/h/35a633/32.png) [@hariseldon3141](https://discuss.elastic.co/u/hariseldon3141)\
**Post date:** [April 6, 2020, 10:26pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-contains-and-intersects/226791/1 "2020-04-06T22:26:33Z")

</div>

Sorry for the newbie question, but these geo\_shape spatial relations seem to be very similar in the results that they produce. I believe that CONTAINS is relatively new in being supported, but what's even the point of it when INTERSECTS seems to do everything that CONTAINS does? Is there something behind the scenes going on, such as performance differences?

I only ask this question because they seem to produce the same results, please excuse my ignorance.

Bonus Question: Does anyone know how to take advantage of [this (#53466)](https://github.com/elastic/elasticsearch/pull/53466)/[this (#39237)](https://github.com/elastic/elasticsearch/issues/39237) fix to support circles on geo\_shape queries? I can use circles to perform CONTAINS/INTERSECTS, is this the "geo\_distance" type query that is mentioned, since anything inside the circle is effectively within the radius distance from the center point?

\*Edit:

This seems to work on the master version of elasticsearch, but not on older versions, so i think that answers the BONUS question.

```auto
body = {
  "_source": "NAME",
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "geo_shape": {
          "LOCATION": {
            "shape": {
              "type": "circle",
              "coordinates": ...,
              "radius": "10km"  
            },
            "relation": "intersects"
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [April 7, 2020, 4:51am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-contains-and-intersects/226791/2 "2020-04-07T04:51:07Z")

</div>

> [@hariseldon3141](#):
>
> relatively new in being supported

Hi  
I dont think intersects and contains produce the same results. If A contains B, A must intersect B. But if A intersects B , A doesn't need to contain B.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [April 7, 2020, 5:21am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-contains-and-intersects/226791/3 "2020-04-07T05:21:34Z")

</div>

### CONTAINS

 ![contains](https://us1.discourse-cdn.com/elastic/original/3X/b/9/b952e656f84c937091d297dbd4a3d37131c99873.png)

The pink shape is wholly contained within the green shape

### INTERSECTS

 ![intersects-interior-boundary](https://us1.discourse-cdn.com/elastic/original/3X/e/6/e657f60d3ad7b178de26886cb7401b9cd8dd3d99.png)

The pink shape overlaps (intersects) with the green shape. The intersection may even just be a shared boundary

 ![intersects-boundary](https://us1.discourse-cdn.com/elastic/original/3X/0/3/038fbbb7d8e59c532af06bc4d9b32634962bcf96.png)

the light pink boundary intersects with the light green boundary. The illustration is not great, but hopefully you get the points (pun intended).

I would suspect `INTERSECTS` would be generally faster than `CONTAINS` because `INTERSECTS` does not need to check every point of a shape to determine that it is contained within another, only that one point overlaps. Consider `CONTAINS` to be a specialized form of `INTERSECTS`.

---

<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:** [May 5, 2020, 5:21am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-contains-and-intersects/226791/4 "2020-05-05T05:21:37Z")

</div>

Closed on May 5, 2020, 5:21am UTC

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