弹性地图中的geo_point字段数组的映射

时间:2016-03-16 21:58:06

标签: elasticsearch indexing mapping

我希望将一些JSON保留为弹性(搜索),看起来有点像这样:

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

Points是弹性中geo_point类型的列表。因为他们需要geo_point值我需要定义索引映射,但我能看到的最接近的是:

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

这意味着让每个点都是具有单个键位置和geo_point值的地图。我只想要geo_points,这可能吗?

2 个答案:

答案 0 :(得分:4)

是。定义映射时,字段内的值可以是单个或特定“类型”的数组。您只需要在此值上插入一个geo_points数组。有些人喜欢这样:




  {
 “名字”:“某个名字”,
 “点”:[
 {lat:41.12,lon:2.023},
 {lat:30,lon:4.1}
 ]
}
  



答案 1 :(得分:4)

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

"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" 
    }
  }
}