6

I try to determine if a polygon (indexed in document) has common point with another shape like a circle.

The Elasticsearch documentation provides 4 types of relation:

  • INTERSECT ;
  • DISJOINCT ;
  • CONTAINS ;
  • WITHIN.

I try to find more information especially from the GeoJSON side without success.

I think the first type could answer my problem but I can't find the difference between the two lasts. The documentation is very short.

Thanks.

Geoffrey
  • 193
  • 3
  • 11

1 Answers1

7

WITHIN will return all documents whose geo_shape field is within the geometric shape specified in the query.

=> In this case, you will specify a geometric shape A in your query and ES will return all documents whose geo_shape field B is located entirely WITHIN that shape A: A contains B

CONTAINS will return all documents whose geo_shape field contains the geometric shape specified in the query.

=> In this case, ES will return all documents whose geo_shape field B CONTAINS the geometric shape A specified in your query: B contains A

Val
  • 207,596
  • 13
  • 358
  • 360
  • 2
    I don't understand the grammatical difference. For me the both means inside something, English is not my primary language. – Geoffrey Nov 14 '16 at 12:53
  • 8
    The difference is that `WITHIN` means `A contains B` and `CONTAINS` means `B contains A`, where `A` is the shape in the query and `B` is the shape in the documents. – Val Nov 14 '16 at 12:58
  • 3
    I can explain in French, too ;) – Val Nov 14 '16 at 13:04
  • 1
    Thanks you very much, I understood, basically it defines the direction of inclusion. – Geoffrey Nov 14 '16 at 13:06