0

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"
}]
}
Community
  • 1
  • 1
Shreyas Rao B
  • 193
  • 4
  • 17

1 Answers1

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}
Toni
  • 121
  • 7
  • Why you have given **"type" : "nested"** ?..I am new to this so. – Shreyas Rao B Apr 20 '16 at 12:29
  • I prefer to use nested data type because it allows data arrays (array of objects) to be indexed and queried independently of the others. You can also use basic object type. – Toni Apr 20 '16 at 12:35
  • Pls check Update 1. I have changed my json file....How do you write a general mapping for that json file? I am bit confused because there **fuelType** and **price** are repeating. how do you write mappings for repeated things? – Shreyas Rao B Apr 20 '16 at 12:44
  • As I can see you have multiple fuelTypes and prices so you want them to repeat. Here you can also use nested object type for prices and just insert data as json. – Toni Apr 20 '16 at 13:16
  • can yu pls give me the mappings? Just like one you have given for earlier..pls – Shreyas Rao B Apr 20 '16 at 13:25
  • "prices": { "type": "nested", "properties": { "fuelType": { "type": "string", }, "price": { "type": "float", }, } – Toni Apr 20 '16 at 13:36
  • can you help me in this also? [See this](http://stackoverflow.com/questions/36762578/how-to-write-template-in-elasticsearch) – Shreyas Rao B Apr 21 '16 at 07:28