【问题标题】:Mapping ElasticSearch GeoPoint Fields映射 ElasticSearch GeoPoint 字段
【发布时间】:2012-08-31 12:09:26
【问题描述】:

我们存储的文档看起来像这样:

{
    "id": "dQesbpxeQniUWXpsnjPQ",
    "title": "Golf in Hamburg, Altona",
    "user": "CtGjEaDxSrhPbf7W7NcH",
    "location": {
        "id": "Q6sZhRHdiS3mP2innbJ9",
        "name": "Hamburg, Altona",
        "lat": 53.55,
        "lon": 9.93333,
        "slug": "hamburg-altona"
    },
    "_type": "announcement"
}

我们需要 announcement.location.slug 成为 not_analyzed(毕竟这是一个蛞蝓)

但是映射不会采取,我们有这些设置:

Tire.index(@@index_name) do
  delete
  create(mappings: {
    announcement: {
      properties: {
        "id"       => { type: 'string', index: 'not_analyzed' },
        "user"     => { type: 'string', index: 'not_analyzed' },
        "location" => {
          type: 'geo_point',
          properties: {
            "slug" => { type: 'string', index: 'not_analyzed' }
          }
        },
        "times"    => { type: 'string', analyzer: 'keyword'   },
        "sport" => {
          "properties" => {
            "slug" => { type: 'string', index: 'not_analyzed' }
          }
        }
      }
    }
  },
  settings: {
    index: {
      number_of_shards: 1,
      number_of_replicas: 0
    }
  })
  refresh
end

注意:curl 语法中的相同映射也不起作用,但对 SO 的可读性较差,因此我发布了 Ruby 代码。

似乎geo_point 正在覆盖文档该部分的所有其他映射。 The documentation 似乎同意。

我确信有一种方法可以使用 lat_lon 选项,但我找不到任何关于它如何工作的文档。 (我假设使用lat_lon 设置映射单个latlon 字段)

也有可能,我曾希望使用the multi field type,但这似乎不适用于主文档属性的整个子树。

如何在不更改整个数据模型的情况下继续操作?

【问题讨论】:

    标签: ruby search geolocation elasticsearch tire


    【解决方案1】:

    恐怕你必须改变你的模型,因为 geo_point 是一个完整的数据类型,你不能在其中添加属性(元)。

    【讨论】:

    • 我们能够很容易地更改to_indexed_hash 方法,并且很好地更新了映射,幸运的是我们的测试套件发现了一堆小错误,所有这些都很容易修复。感谢您确认我的假设!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-27
    • 2017-10-13
    • 2017-05-18
    • 2019-07-04
    • 1970-01-01
    相关资源
    最近更新 更多