What is the difference between CONTAINS and INTERSECTS?

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)/this (#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?


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

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

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.


The pink shape is wholly contained within the green shape


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

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.

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