无法让geo_point与盆景合作制作 Heroku



我试图在Heroku/Bonsai上使用geo_point字段,但它不想工作。

它在本地工作,但每当我在Heroku/Bonsai上检查索引的映射时,它都会说我的字段是字符串:"coordinates":{"type":"string"}

我的映射如下:

tire.mapping do
  ...
  indexes :coordinates, type: "geo_point", lat_lon: true
  ...
end

我的to_indexed_json是这样的:

def to_indexed_json
  {
    ...
    coordinates: map_marker.nil? ? nil : [map_marker.latitude, map_marker.longitude].join(','),
    ...
  }.to_json
end

在Heroku上的控制台中,我尝试了MyModel.mappingMyModel.index.mapping,第一个正确地使用了:coordinates=>{:type=>"geo_point", :lat_lon=>true}

以下是我如何做到这一点的。索引名称'myindex'类型名称'myindextype'

在本地机器上

curl -XGET https://[LOCAL_ES_URL]/myindex/myindextype/_mapping

将输出保存到.json文件中。示例:typedefinition.json(或手工构建一个)

{
  "myindextype":{
    "properties":{
      "dataone":{"type":"string"},
      "datatwo":{"type":"double"},
      "location":{"type":"geo_point"},
      "datathree":{"type":"long"},
      "datafour":{"type":"string"}
    }
  }
}

在heroku上输入命令

heroku config

并获得BONSAI_URL。将其放在以下执行命令中,以代替[BONSAI_URL]。(https://asdfasdfdsf:asdfadf@asdfasdfasdf.us-east-1.bonsai.io/myindex)

curl -XDELETE https://[BONSAI_URL]/myindex
curl -XPOST https://[BONSAI_URL]/myindex
curl -XPUT -d@typedefinition.json https://[BONSAI_URL]/myindex/myindextype/_mapping 
curl -XGET https://[BONSAI_URL]/myindex/myindextype/_mapping
  1. 删除inda(如果存在)
  2. 创建一个空索引
  3. 使用.json文件作为映射的定义
  4. 获取新映射以确保其有效

最新更新