0
votes

Can anyone guide me to change the mapping type of location to geo_point.?

Service: Aws ElasticSearch (6.2 Version) Database: dynamodb

I am using aws elastic search service to filter values based on my location. As per the documentation i have created a trigger lambda function dbtoEs which is a python code soon after the record is added its indexed.

Since my location type in dynamodb is type Location { lat: Float lon: Float }

When i go to Aws ElasticSearch and check in indices the mapping type for this field is also location { lat float lon float }

As per the Elastic geo distance query (https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-geo-distance-query.html) the mapping type of location should be geo_point

Example of search query filter

    filter:[ 
        { 
          geo_distance:{ 
             distance:"2000 km",
             location:{ 
                  lon:77.676,
                  lat:12.998
              },
           }
        },
      { 
        range:{ 
            createdAt:{ 
            gte:"now-1d/d"
           }
         }
        }
       ],

Search Response

 { 
   "took":4,
   "timed_out":false,
   "_shards":{ 
      "total":5,
      "successful":4,
      "skipped":0,
      "failed":1,
      "failures":[ 
         { 
            "shard":4,
            "index":"spot",
            "node":"*******",
            "reason":{ 
               "type":"query_shard_exception",
               "reason":"failed to find geo_point field 
                         [location]",
               "index_uuid":"**********",
               "index":"***"
            }
         }
      ]
   },
   "hits":{ 
      "total":0,
      "max_score":null,
      "hits":[ 

      ]
   }
}


**Result Required: Filtered results should be based on location**
2

2 Answers

0
votes

You need to create mapping before first record is indexed. In absence of mapping elasticsearch interprets the type dynamically. In this case it is float.

Look for mapping api for elasticsearch and create mapping for geo_point field using lat longs.

0
votes

I've solved the problem

Help: Initially I faced difficulty how to change the type alone, when I implemented elastic search with dynamodb it creates index automatically as soon a record is added in dynamo DB, We cannot change the type of location in dynamo DB as it doesn't support. We have to change type in Elasticsearch index so follow the steps below

1) Change Elastic Search mapping type manually using kibana UI. By default, the mapping type will be the same as the column data type we have to change the type of location to geo_point.

2) GET /xyz/_mappings It returns all the mappings with types Copy the mappings

3) DELETE XYZ/ Delete the mappings

4) PUT XYZ/ Change the mapping type of location to geo_point in the copied mappings and create mappings using PUT XYZ { mappings: ... }

Happy Day