elasticsearch geo_distance查询给我错误如何编写geo_distance查询?

时间:2012-10-01 12:31:38

标签: 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":"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

我怎样才能让它发挥作用?

0 个答案:

没有答案