如何在Elasticsearch(geo数据类型)中使用以下数据索引文档?

<west>5.8663152683722</west>
<north>55.0583836008072</north>
<east>15.0418156516163</east>
<south>47.2701236047002</south>

我尝试了geo_point及其用于lon和lat的工作,不确定如何保存此数据。非常感谢您的帮助。

最佳答案

在同步之前,您必须使用geo_shape datatype并将XML(我认为)半点转换为线字符串或多边形。

我要去一个多边形。
让我们可视化常规的cardinal directions:

             North (+90)
               |
(-180) West  ——+—— East (+180)
               |
             South (-90)

geo_shape需要类似GeoJSON的输入,因此您需要五个坐标点,第一个和最后一个是相同的(根据GeoJSON spec)。

因此,从TurfJS借用并逆时针从左下角开始,
const lowLeft = [west, south];
const topLeft = [west, north];
const topRight = [east, north];
const lowRight = [east, south];

return
[
  [
    lowLeft,
    lowRight,
    topRight,
    topLeft,
    lowLeft
  ]
]

最后,让我们创建索引并将您的电话号码插入
PUT /example
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_shape"
      }
    }
  }
}
POST /example/_doc
{
  "location":{
    "type":"polygon",
    "coordinates":[
      [
        [
          5.8663152683722,
          47.2701236047002
        ],
        [
          15.0418156516163,
          47.2701236047002
        ],
        [
          15.0418156516163,
          55.0583836008072
        ],
        [
          5.8663152683722,
          55.0583836008072
        ],
        [
          5.8663152683722,
          47.2701236047002
        ]
      ]
    ]
  }
}

然后验证正方形的中心是否确实在索引多边形内:
GET example/_search
{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "point",
          "coordinates": [
            10.45406545999425,
            51.1642536027537
          ]
        },
        "relation": "intersects"
      }
    }
  }
}

10-04 12:08
查看更多