Mapping for array of geo_point fields in elastic

大憨熊 提交于 2020-01-14 10:42:36

问题


I'd like to persist some JSON to elastic(search) that looks a little like this:

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

Points being a list of the type geo_point in elastic. Because they're geo_point values I need to define the index mapping, but the closest I can see is to do this:

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

Which would mean having each point be a map with a single key of location and a geo_point value. I just want the geo_points, is this possible?


回答1:


You can define your mapping as below :

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



回答2:


Yes. When you define a mapping, the values inside field can be single or array of the specific "type". You need only insert on this value a array of geo_points. Some like this:

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


来源:https://stackoverflow.com/questions/36047741/mapping-for-array-of-geo-point-fields-in-elastic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!