地理位置距离过滤器

Mar*_*Lau 5 elasticsearch

我收到来自Elasticsearch的400错误的请求错误。该错误是一个很大的块响应,但我认为这是关键部分。

failed to find mapper for [location] for geo distance based sort
Run Code Online (Sandbox Code Playgroud)

我正在使用ES 1.5.1进行查询。我的查询是:

{
  query: {
    filtered: {
      query: {
        match: {
          title:"amsterdam*"
        }
      }
    }
  }, sort: [
       {
         _geo_distance: {
           location: {lat:0, lon:0}, order:"asc", unit:"miles"
         }
       }
     ]
}
Run Code Online (Sandbox Code Playgroud)

我已经格式化了查询,就像这里的文档一样。我错过了一步吗?

这是我当前的映射:

{
  "gb": {
    "mappings": {
      "store": {
        "dynamic":"false",
        "properties": {
          "active": {
            "type": "b??oolean"
          },
          "deleted": {
            "type": "boolean"
          },
          "location": {
            "type":"geo_point"
          },
          "open": {
            "ty??pe": "boolean"
          },
          "suspended": {
            "type": "boolean"
          },
          "title": {
            "type":"string"
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Jak*_*ski 0

你的查询没问题。该字段location必须具有映射类型geo_point,看起来确实如此。

试试这个 Marvel Sense 脚本:

(通过运行安装Marvel bin/plugin -i elasticsearch/marvel/latest

put geo
put geo/geo/_mapping
{
  "properties": {
    "location": {
          "type": "geo_point",
          "geohash" : true
    }
  }
}
put geo/geo/1
{
  "location": {
    "lat": 0.1,
    "lon": 0.1
  }
}
put geo/geo/2
{
  "location": {
    "lat": 50.1,
    "lon": 7.1
  }
}
put geo/geo/3
{
  "location": {
    "lat": 5.1,
    "lon": 3.1
  }
}
get geo/geo/_search
{
  "query": {
        "match_all": {
        }
    }, 
  "sort": [
       {
         "_geo_distance": {
           "location": {"lat":0, "lon":0}, 
           "order":"asc", 
           "unit":"km"
         }
       }
     ]
}
get geo/_mapping
Run Code Online (Sandbox Code Playgroud)

由于某种原因,Sense 中的搜索查询对我不起作用。通过curl,它可以毫无问题地工作:

curl -XGET '0:9200/geo/geo/_search?pretty' -d@query.json