diff --git a/app/models/application.rb b/app/models/application.rb index 19c649e19..0e07c3195 100644 --- a/app/models/application.rb +++ b/app/models/application.rb @@ -30,7 +30,11 @@ class Application < ApplicationRecord def search_data # lat and lon need to be symbols (rather than strings) in search_data # to get valid data come through searchkick for some reason - attributes.symbolize_keys.merge(location: { lat:, lon: lng }) + r = attributes.symbolize_keys.merge(location: { lat:, lon: lng }) + # lonlat is encoded geo data and elasticsearch is unhappy to index this. So skip it. + # We're capturing the geodata anyway via the "location" key + r.delete(:lonlat) + r end # For the benefit of kaminari. Also sets the maximum number of diff --git a/spec/models/application_spec.rb b/spec/models/application_spec.rb index 817c63156..70fe77480 100644 --- a/spec/models/application_spec.rb +++ b/spec/models/application_spec.rb @@ -213,4 +213,10 @@ it { expect(application.official_submission_period_expired?).to be false } end end + + describe "#search_data" do + it "does not try indexing the geo data directly because elasticsearch can't handle this" do + expect(create(:geocoded_application).search_data).not_to have_key(:lonlat) + end + end end