Ruby on rails 3 elasticsearch地理位置距离查询给我错误如何编写地理位置距离查询?
我有一个表,Ruby on rails 3 elasticsearch地理位置距离查询给我错误如何编写地理位置距离查询?,ruby-on-rails-3,search,search-engine,
elasticsearch,Ruby On Rails 3,Search,Search Engine,
elasticsearch,我有一个表,schools,其中包含以下字段:id、姓名、地址、城市、州、邮政编码、纬度和经度 我想用经纬度搜索12公里以内的学校;我正在使用此查询,但它不起作用 curl -X GET "http://localhost:9200/schools/school/_search?=true" -d '{"filter" : {"geo_distance" : {"distance" :"12km", "location": "40,-70"}}}' 我得到以下错误: { "error":"Se
schools
,其中包含以下字段:id、姓名、地址、城市、州、邮政编码、纬度和经度
我想用经纬度搜索12公里以内的学校;我正在使用此查询,但它不起作用
curl -X GET "http://localhost:9200/schools/school/_search?=true" -d '{"filter" : {"geo_distance" : {"distance" :"12km", "location": "40,-70"}}}'
我得到以下错误:
{
"error":"SearchPhaseExecutionException[
Failed to execute phase [query], total failure;
shardFailures {[_na_][schools][0]: No active shards}{[_na_][schools][1]:
No active shards}{[_na_][schools][2]: No active shards}{[_na_][schools][4]:
No active shards}{[WJV55VsxQU-XW8VPmXImwA][schools][3]:
RemoteTransportException[[Archie Corrigan][inet[/192.168.1.109:9300]][search/phase/query]]; nested:
SearchParseException[[schools][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [
{\"filter\" :
{\"geo_distance\" :
{\"distance\" :\"12km\", \"location\": \"40,-70\"}
}
}]
]
]; nested: QueryParsingException[[schools] failed to find geo_point field [location]];}]",
"status":500
}
rails中的模型配置
# ElasticSearch integration
include Tire::Model::Callbacks
include Tire::Model::Search
include Search::ReloadHelper
tire do
settings({
:analysis => {
:filter => Search::Filters.hs_name_filters,
:analyzer => Search::Analyzers.hs_name_analyzers
}
})
mapping do
indexes :id, :type => 'integer', :index => :not_analyzed
indexes :name, :type => 'string', :analyzer => :hs_name_analyzer
indexes :address, :type => 'string', :index => :not_analyzed
indexes :city, :type => 'string', :analyzer => :hs_name_analyzer
indexes :state, :type => 'string', :index => :not_analyzed
indexes :zip, :type => 'integer', :index => :not_analyzed
indexes :location, :type => 'geo_point', :lat_lon => true
end
end
def to_indexed_json
{
:id => id,
:name => name,
:address => address,
:city => city,
:state => state,
:zip => zip,
:location => {
:lat => latitude,
:lon => longitude
}
}.to_json
end
我怎样才能让它工作?@CAMOBAP;请不要继续编辑同一帖子。。。尤其是如果你的编辑太小的话。如果要编辑某些内容,请确保一次性修复所有内容。我们可以查看位置字段的映射吗?elasticsearch的错误非常明显,它无法作为地理点字段找到它。