i am getting not a geopoint error. also tried with string instead of array, deleting index and recreating
{
"error_code": "103",
"error_message": "[400] {"errormd5-acaf913650f8e36f2dd6672916d4eefb:"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[nja_gc2ERMud-T3_GoRCNw][barter_li_application_development][3]: SearchParseException[[barter_li_application_development][3]: query[title:bb_],from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"prefix\":{\"title\":\"bb\"}},\"filter\":{\"geo_distance\":{\"distance\":\"50km\",\"lon_lat\":{\"lon\":77.5667,\"lat\":12.9667}}}}]]]; nested: QueryParsingException[[barter_li_application_development] field [lon_lat] is not a geo_point field]; }{[nja_gc2ERMud-T3_GoRCNw][barter_li_application_development][4]: SearchParseException[[barter_li_application_development][4]: query[title:bb_],from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"prefix\":{\"title\":\"bb\"}},\"filter\":{\"geo_distance\":{\"distance\":\"50km\",\"lon_lat\":{\"lon\":77.5667,\"lat\":12.9667}}}}]]]; nested: QueryParsingException[[barter_li_application_development] field [lon_lat] is not a geo_point field]; }{[nja_gc2ERMud-T3_GoRCNw][barter_li_application_development][1]: SearchParseException[[barter_li_application_development][1]: query[title:bb_],from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"prefix\":{\"title\":\"bb\"}},\"filter\":{\"geo_distance\":{\"distance\":\"50km\",\"lon_lat\":{\"lon\":77.5667,\"lat\":12.9667}}}}]]]; nested: QueryParsingException[[barter_li_application_development] field [lon_lat] is not a geo_point field]; }{[nja_gc2ERMud-T3_GoRCNw][barter_li_application_development][2]: SearchParseException[[barter_li_application_development][2]: query[title:bb_],from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"prefix\":{\"title\":\"bb\"}},\"filter\":{\"geo_distance\":{\"distance\":\"50km\",\"lon_lat\":{\"lon\":77.5667,\"lat\":12.9667}}}}]]]; nested: QueryParsingException[[barter_li_application_development] field [lon_lat] is not a geo_point field]; }{[nja_gc2ERMud-T3_GoRCNw][barter_li_application_development][0]: SearchParseException[[barter_li_application_development][0]: query[title:bb*],from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"prefix\":{\"title\":\"bb\"}},\"filter\":{\"geo_distance\":{\"distance\":\"50km\",\"lon_lat\":{\"lon\":77.5667,\"lat\":12.9667}}}}]]]; nested: QueryParsingException[[barter_li_application_development] field [lon_lat] is not a geo_point field]; }]","statusmd5-acaf913650f8e36f2dd6672916d4eefb:400}"
}
module Searchable
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
# Customize the index name
#
index_name [Rails.application.engine_name, Rails.env].join('_')
# Set up index configuration and mapping
#
settings index: { number_of_shards: 1, number_of_replicas: 0 } do
mapping do
indexes :title, analyzer: 'not_analyzed'
indexes :lon_lat, type: 'geo_point'
end
end
def as_indexed_json(options={})
{
title: self.title,
lon_lat: lon_lat
}
end
def lon_lat
[self.location.longitude.to_f, self.location.latitude.to_f]
end
def self.search(query)
__elasticsearch__.search(
{
query: { prefix: { title: query[:title] } },
filter: {
geo_distance: {
distance: query[:radius],
lon_lat: {
lon: query[:longitude],
lat: query[:latitude]
}
}
}
}
)
end
end
end
i am using elasticsearch version 1.0.2 and elasticsearch-rails/model (0.1.1)
So, first of all, post the resulting mapping for your index, otherwise everything is a guess.
Second, you're sending the geolocation attributes as an Array of [lon,lat], and then you query it as lon_lat.lon and lon_lat.lat. Apart from a really bad naming here (why not eg. location), I would send the data as properties. I would _never_ used the Array notation, because there are so many problems with it, since it switches the common lat,lon order.
Try to fix these errors, post the mapping.
the previous one with array had location: double mapping
{"mappings":{"book":{"properties":{"lon_lat":{"type":"double"},"title":{"type":"string"}}}}}}
i changed to properties instead of array and rename to location . the mapping is {"barter_li_application_development":{"mappings":{"book":{"properties":{"location":{"properties":{"lat":{"type":"string"},"lon":{"type":"string"}}},"title":{"type":"string"}}}}}}
now i get failed to find geo_point field [location]
mapping do
indexes :title, analyzer: 'not_analyzed'
indexes :location, type: 'geo_point'
end
def location_coor
{ "lat" => self.location.latitude.to_s, "lon" => self.location.longitude.to_s}
end
def as_indexed_json(options={})
{
title: self.title,
location: location_coor
}
end
the type :geopoint is not setting geopoint
but i was able to create a geopoint field using curl
curl -XPUT http://localhost:9200/us_large_cities -d '{"mappings": {"city": {"properties": {"city": {"type": "string"}, "state": {"type": "string"}, "location": {"type": "geo_point"} } } } } '
curl -XPOST http://localhost:9200/us_large_cities/city/ -d '{"city": "Anchorage", "state": "AK","location": {"lat": "61.2180556", "lon": "-149.9002778"}}'
curl -XPOST http://localhost:9200/us_large_cities/city/ -d '{"city": "Birmingham", "state": "AL","location": {"lat": "33.5206608", "lon": "-86.8024900"}}'
curl -XPOST http://localhost:9200/us_large_cities/city/ -d '{"city": "Huntsville", "state": "AL","location": {"lat": "34.7303688", "lon": "-86.5861037"}}'
curl -XPOST http://localhost:9200/us_large_cities/city/ -d '{"city": "Mobile", "state": "AL","location": {"lat": "30.6943566", "lon": "-88.0430541"}}'
mapping
:{"mappings":{"city":{"properties":{"city":{"type":"string"},"location":{"type":"geo_point"},"state":{"type":"string"}}}}}}
I don't know what you're doing (the lack of formatting in your message doesn't help), but when I define a geo point in a mapping, recreate the index, I get an index with correct mapping:
class Article < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
mapping do
indexes :title, type: 'string'
indexes :location, type: 'geo_point'
end
def as_indexed_json(options={})
as_json(only: 'title').merge location: { lat: self.lat, lon: self.lon }
end
end
Article.__elasticsearch__.create_index! force: true
# 2014-05-24 13:03:18 +0200: DELETE http://localhost:9200/articles [status:200, request:0.284s, query:n/a]
# 2014-05-24 13:03:18 +0200: < {"acknowledged":true}
# 2014-05-24 13:03:18 +0200: HEAD http://localhost:9200/articles [status:404, request:0.004s, query:N/A]
# 2014-05-24 13:03:18 +0200: <
# 2014-05-24 13:03:18 +0200: [404]
# 2014-05-24 13:03:18 +0200: PUT http://localhost:9200/articles [status:200, request:0.433s, query:n/a]
# 2014-05-24 13:03:18 +0200: > {"settings":{},"mappings":{"article":{"properties":{"title":{"type":"string"},"location":{"type":"geo_point"}}}}}
# 2014-05-24 13:03:18 +0200: < {"acknowledged":true}
Article.create title: 'Foo', lat: 40, lon: 50
# 2014-05-24 13:03:49 +0200: PUT http://localhost:9200/articles/article/4 [status:201, request:0.084s, query:n/a]
# 2014-05-24 13:03:49 +0200: > {"title":"Foo","location":{"lat":40,"lon":50}}
# 2014-05-24 13:03:49 +0200: < {"_index":"articles","_type":"article","_id":"4","_version":1,"created":true}
Article.__elasticsearch__.mapping.to_hash
# => {:article=> {:properties=>{:title=>{:type=>"string"}, :location=>{:type=>"geo_point"}}}}
Thanks for your reply!
The issue was with i never did this Article.elasticsearch.create_index! force: true
i just ran bundle exec rake environment elasticsearch:import:model CLASS='Article'. i have not created index at first. the instruction was at elasticsearch-model https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model#index-configuration.
I also get a similar issue while implementing this:
include Elasticsearch::Persistence::Repository
include Elasticsearch::Persistence::Repository::DSL
index_name "merchant_#{Rails.env}"
settings index: { number_of_shards: 1 } do
mappings do
indexes :coordinates, type: 'geo_point'
end
end
The error message is:
Elasticsearch::Transport::Transport::Errors::BadRequest:
[400] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [coordinates : {type=geo_point}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [properties]: Root mapping definition has unsupported parameters: [coordinates : {type=geo_point}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [coordinates : {type=geo_point}]"}},"status":400}
2.5.1 :001 > PersistenceLayer::MerchantDetailsRepository.settings
=> #<Elasticsearch::Model::Indexing::Settings:0x00007fae3f6d2be0 @settings={:index=>{:number_of_shards=>1}}>
I'm using elasticsearch 7.0.0. @karmi thoughts?
Most helpful comment
I don't know what you're doing (the lack of formatting in your message doesn't help), but when I define a geo point in a mapping, recreate the index, I get an index with correct mapping: