在Elasticsearch中使用copy_to将坐标复制到字段geo_point类型

时间:2020-04-08 14:07:23

标签: elasticsearch elastic-stack

我正在尝试在Elasticsearch中使用地理编码,我有一个索引,其中包含两个不同的唯一字段,即纬度和经度。两者都存储为double,我想使用copy来实现elasticsearch的功能并将两个字段值都复制到具有geo_point类型的第三个字段中。我尝试这样做,但是没有按预期工作。

{
  "mappings": {
    "properties": {
      "unique_id": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "location_data": {
        "properties": {
          "latitude": {
            "type": "float",
            "copy_to": "last_location"
          },
          "longitude": {
            "type": "float",
            "copy_to": "last_location"
          },
          "last_location": {
            "type": "geo_point"
          }
        }
      }
    }
  }
}

当我索引示例文档时,例如

{
  "unique_id": "12345_mytest",
  "location_data": {
    "latitude": 37.16,
    "longitude": -124.76
  }
}

您将能够在新映射中看到,应该在location_data对象内部的last_location字段也在根级别填充了geo_point以外的其他数据类型。

{
    "mappings" : {
      "properties" : {
        "last_location" : {
          "type" : "float"
        },
        "location_data" : {
          "properties" : {
            "last_location" : {
              "type" : "geo_point",
              "store" : true
            },
            "latitude" : {
              "type" : "float",
              "copy_to" : [
                "last_location"
              ]
            },
            "longitude" : {
              "type" : "float",
              "copy_to" : [
                "last_location"
              ]
            }
          }
        },
        "unique_id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword"
            }
          }
        }
      }
    }
  }

此外,当我在该字段中查询时,无法获得预期的结果。

这是行不通的,其他任何想法或方法都行不通。我知道我可以从源代码本身或通过在索引之前更改数据来做到这一点,但我不必奢侈地立即做到这一点。任何其他通过更改映射的方式都非常受欢迎。在此先感谢您完成此操作的任何指示。

谢谢 突击

0 个答案:

没有答案
相关问题