0

我在理解用于形成 GeoDistance 查询的 DSL 语法时遇到了一些麻烦(获取距某个点一定距离内的所有条目);

目前,在我的 ES 索引"places" -> "shops"中,id = 1我有一个示例条目;

{
  _index: "places",
  _type: "shops",
  _id: "1",
  _version: 5,
  found: true,
  _source: {
    location: {
      lat: 50,
      lon: 50
    },
    name: "coffee store",
    posted: "2014-09-12T08:53:01.673Z"
  }
}

然后,使用 Elastic4s DSL,我正在构建一个搜索查询;

val nearbyStoresFuture:Future[SearchResponse] = client execute {
  search in "places" -> "shops" filter {
    geoDistance("location") point(lat, lon) distance(distance)
  }
}
nearbyStoresFuture onComplete {
  case Success(s) => {
    s
    client.close
  }
  case Failure(t) => {
    t
    client.close
  }
}

在这种情况下:

lat: Double = 50.0
lon: Double = 50.0
distance: String = "50km"

所以无论如何,如果查询是正确的,这应该给我包含 ES 中的条目的结果,因为它与条目位于同一点,因此在 50 公里的距离内。

查询成功但结果为空。

编辑:这是映射的样子;

ES.execute {
  create index "places" mappings(
    "shops" as (
      "location" typed GeoPointType,
      "name" typed StringType,
      "posted" typed DateType
      )
    )
}

这有什么问题?

4

1 回答 1

1

这不是一个 elastic4s 问题,而是一个一般的 elasticsearch 问题:tl;dr 您没有为任何字段编制索引。

索引数据时,您指定索引哪些字段,然后将这些字段用于搜索。此外,您可以存储一个文档,当搜索匹配该文档时可以获取该文档。如果您希望能够返回原始文档,但希望在索引时使用字段的子集或派生字段,这将很有用。

在elastic4s中

index into "myindex"->"mytype" fields ("name"->name, "location"->latlong) source srcdoc

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-source-field.html http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/index-doc .html

于 2014-09-12T11:18:24.190 回答