vikas gupta vikas gupta - 6 months ago 18
PHP Question

geo_point for location field within array field

I have data in elasticsearch like this

"id": "edff12sd3"
"main_array": [
{
"id": "2308",
"name": "Grey Area",
"location": {
"lat": 28.5696577,
"lon": 77.3229933
}
}
,
{
"id": "2274",
"name": "Tribute to The Beatles by Atul Ahuja- Live Music",
"location": {
"lat": 29.5696577,
"lon": 77.3229933
}
}


Now i want to set geo_point for location field. I have tried in this way

{
"mappings": {
"search_data": {
"properties": {
"main_array.location": {
"type": "geo_point"
}
}
}
}
}


but it throws me error

"type": "mapper_parsing_exception",
"reason": "Field name [main_array.location] cannot contain '.'"


can you please help me out. thanks

Val Val
Answer

location is a property of the objects you store in main_array, so try like this:

{
  "mappings": {
    "search_data": {
      "properties": {
        "main_array": {
          "properties": {
            "location": {
              "type": "geo_point"
            }
          }
        }
      }
    }
  }
}

Note that as of ES 2.0 field names may not contain dots