在弹性中映射 geo_point 个字段数组

Mapping for array of geo_point fields in elastic

我想坚持一些 JSON 到 elastic(search),看起来有点像这样:

{
  "name": "value",
  "points": [
    { "lat": 0.0, "lon": 0.0 },
    { "lat": 1.0, "lon": 1.0 }
  ]
}

点是弹性类型 geo_point 的列表。因为它们是 geo_point 值,所以我需要定义索引映射,但我能看到的最接近的是这样做:

"place": {
  "properties": {
    "name": {
      "type": "string"
    },
    "points": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}

这意味着每个点都是一张地图,其中包含一个位置键和一个 geo_point 值。我只想要 geo_points,这可能吗?

是的。定义映射时,字段内的值可以是单个值,也可以是特定"type"的数组。您只需要在此值上插入一个 geo_points 的数组。有些像这样:

{
  "name": "some name",
  "points": [
    { lat: 41.12, lon: 2.023 },
    { lat: 30, lon: 4.1 }
  ]
}

您可以按如下方式定义您的映射:

"place": {
  "properties": {
    "name": {
      "type": "string"
    },
    "points": {  // <--  it can also be a multi-valued field if you insert multiple values, as skal88 mentioned, your json would perfectly fit in this mapping.
      "type": "geo_point" 
    }
  }
}