【问题标题】:Aws Elasticsearch: How to change mapping type of location { lat: float, lon: float} to geo_pointAws Elasticsearch:如何将位置 { lat: float, lon: float} 的映射类型更改为 geo_point
【发布时间】:2020-03-02 14:46:03
【问题描述】:

谁能指导我将位置的映射类型更改为geo_point。

服务:Aws ElasticSearch(6.2 版本) 数据库:dynamodb

我正在使用 aws 弹性搜索服务根据我的位置过滤值。 根据文档,我创建了一个触发器 lambda 函数 dbtoEs,它是在记录被添加索引后不久的 python 代码。

因为我在 dynamodb 中的位置类型是 输入位置 { 纬度:浮动 lon:浮点数 }

当我转到 Aws ElasticSearch 并检查索引时,该字段的映射类型也是 地点 { 纬度浮动 浮子 }

根据弹性地理距离查询 (https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-geo-distance-query.html),位置的映射类型应为 geo_point

搜索查询过滤器示例

    filter:[ 
        { 
          geo_distance:{ 
             distance:"2000 km",
             location:{ 
                  lon:77.676,
                  lat:12.998
              },
           }
        },
      { 
        range:{ 
            createdAt:{ 
            gte:"now-1d/d"
           }
         }
        }
       ],

搜索响应

 { 
   "took":4,
   "timed_out":false,
   "_shards":{ 
      "total":5,
      "successful":4,
      "skipped":0,
      "failed":1,
      "failures":[ 
         { 
            "shard":4,
            "index":"spot",
            "node":"*******",
            "reason":{ 
               "type":"query_shard_exception",
               "reason":"failed to find geo_point field 
                         [location]",
               "index_uuid":"**********",
               "index":"***"
            }
         }
      ]
   },
   "hits":{ 
      "total":0,
      "max_score":null,
      "hits":[ 

      ]
   }
}


**Result Required: Filtered results should be based on location**

【问题讨论】:

    标签: amazon-web-services react-native elasticsearch


    【解决方案1】:

    您需要在索引第一条记录之前创建映射。在没有映射的情况下,elasticsearch 会动态解释类型。在这种情况下,它是浮动的。

    查找用于 elasticsearch 的映射 api 并使用 lat long 为 geo_point 字段创建映射。

    【讨论】:

      【解决方案2】:

      我已经解决了问题

      帮助:最初我遇到了如何单独更改类型的困难,当我使用 dynamodb 实现弹性搜索时,它会在 dynamo DB 中添加记录后自动创建索引,我们无法更改 dynamo DB 中的位置类型因为它不支持。我们必须更改 Elasticsearch 索引中的类型,因此请按照以下步骤操作

      1) 使用 kibana UI 手动更改 Elastic Search 映射类型。 默认情况下,映射类型将与列数据类型相同,我们必须将位置类型更改为geo_point。

      2) 获取 /xyz/_mappings 它返回所有类型的映射 复制映射

      3) 删除 XYZ/ 删除映射

      4) 放置 XYZ/ 在复制的映射中将位置的映射类型更改为 geo_point 和 使用创建映射 放置 XYZ { 映射:... }

      快乐的一天

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-06
        • 1970-01-01
        • 2018-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-10
        • 2023-04-09
        相关资源
        最近更新 更多