How to write mappings in elsaticsearch for geopoint having lat lon and alt?

你离开我真会死。 提交于 2020-01-25 18:44:46

问题


My_Json_File

{
"addressInfo": {
    "city": "Wimsheim",
    "postcode": "71299",
    "geopoint": {
        "lon": 48.845877,
        "lat": 8.821861,
        "alt": 0.0
    }
},
"_id": "ac169008-aa5b-4b09-aa9e-3bf3018f316d"
}    
  • Pls give suggestion on how encounter this "alt" field in geopoint and "_id" field and also write a suitable mappings for above JSON file.

Update 1

My_Json_File

{
"_id": "ac169008-aa5b-4b09-aa9e-3bf3018f316d"
"addressInfo": {
    "city": "Wimsheim",
    "postcode": "71299",
    "geopoint": {
        "lon": 48.845877,
        "lat": 8.821861,
        "alt": 0.0
    }
},
"prices": [{
    "fuelType": "DIESEL",
    "price": "52.09"
}, {
    "fuelType": "PETROL",
    "price": "66.20"
},{
   "fuelType": "AUTOGAS",
    "price": "66.20"
}]
}

回答1:


On your place I would move "alt" out of geopoint and use mapping type "geo_point" which provides a lot of other options for further operations on geopoint field.

It would looks like:

{
    "_id": "ac169008-aa5b-4b09-aa9e-3bf3018f316d"
    "addressInfo": {
        "city": "Wimsheim",
        "postcode": "71299",
        "geopoint": {
            "lon": 48.845877,
            "lat": 8.821861,
        },
        "alt": 0.0
    },
} 

and mapping should look like:

  "properties": {
    "_id": {
      "type": "string"
    },
    "addressInfo": {
      "type": "nested",
      "properties": {
        "city": {
          "type": "string",
        },
        "postcode": {
          "type": "integer",
        },
        "alt": {
          "type": "float",
        },
        "geopoint": {
          "type": "geo_point",
        },
      },
    },
  },

where geo_point type field receives data like:

{"lat": 8.821861, "lon": 48.845877}


来源:https://stackoverflow.com/questions/36737559/how-to-write-mappings-in-elsaticsearch-for-geopoint-having-lat-lon-and-alt

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