From 40bee0a05c8b5aef20a435a9c7b048ba3992f94e Mon Sep 17 00:00:00 2001 From: will-r Date: Wed, 21 Dec 2016 07:50:34 +0000 Subject: [PATCH] 'contains' relation only available in ES 2.2+ --- README.md | 2 +- test/geo_shape_test.rb | 20 +++++++++++--------- test/test_helper.rb | 4 ++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e743cf6..109f1d7 100644 --- a/README.md +++ b/README.md @@ -925,7 +925,7 @@ Any geospatial data type can be used in the index or in the search. It is up to See the [Elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html) for details. GeoJSON coordinates are usually given as an array of `[lon, lat]` points but this often causes swapping errors so searchkick can also take objects with `lon` and `lat` keys. -Elasticsearch is sensitive about geo_shape validity. For example it will throw an exception if a polygon contains two consecutive identical points, or is not properly closed. You probably want to validate the data during indexing. +Elasticsearch is sensitive about geo_shape validity. For example it will throw an exception if a polygon contains two consecutive identical points, intersects itself or is not properly closed. ### Geospatial searching diff --git a/test/geo_shape_test.rb b/test/geo_shape_test.rb index 11c6f5a..26adf88 100644 --- a/test/geo_shape_test.rb +++ b/test/geo_shape_test.rb @@ -102,21 +102,19 @@ class GeoShapeTest < Minitest::Test } }, Region - # contains - assert_search "*", ["Region A"], { + # with search + assert_search "witch", ["Region A"], { where: { territory: { geo_shape: { type: "envelope", - relation: "contains", - coordinates: [[32, 33], [33, 32]] + coordinates: [[28, 42], [32, 38]] } } } }, Region - # with search - assert_search "witch", ["Region A"], { + assert_search "ginger hair", [], { where: { territory: { geo_shape: { @@ -126,18 +124,22 @@ class GeoShapeTest < Minitest::Test } } }, Region + end - assert_search "ginger hair", [], { + def test_geo_shape_contains + skip if elasticsearch_below22? + + assert_search "*", ["Region A"], { where: { territory: { geo_shape: { type: "envelope", - coordinates: [[28, 42], [32, 38]] + relation: "contains", + coordinates: [[32, 33], [33, 32]] } } } }, Region end - end diff --git a/test/test_helper.rb b/test/test_helper.rb index da55df2..8464a30 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -25,6 +25,10 @@ def elasticsearch_below50? Searchkick.server_below?("5.0.0-alpha1") end +def elasticsearch_below22? + Searchkick.server_below?("2.2.0") +end + def elasticsearch_below20? Searchkick.server_below?("2.0.0") end -- libgit2 0.21.0