How to write mappings in elsaticsearch for geopoin

2019-09-08 18:02发布

问题:

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}