Geo_point mapping from Couchbase to Elasticsearch


(Vatsal Patel) #1

I have geo location stored in Cochbase with below format,

"location": {
"lat": 40.722,
"lon": -73.989
}

Now, How can i mapped this value to Elasticsearch?. I want to perform geo_distance sorting on that.Thank you.


(David Pilato) #2

You need to define a mapping for this location field.
And set it as geo_point


(Vatsal Patel) #3

Can i define dynamically.Like below.

"couchbaseDocument": {
"dynamic_templates": [
{
"documents_to_es": {
"mapping": {
"type": "geo_point",
"lat_lon"="true"
},
"match_mapping_type": "double",
"match": "*"
}
}
]
},

Because when i am not applying mapping, Elasticsearch map it as a "double".


(David Pilato) #4

Please format your code when posting.

I remember that couchbase defines a template. You need to change it and defines location as a geo_point.

Look at:

Note that in your case, you know for sure that location is a geo point so you don't need to apply a dynamic template but just define the right mapping for the field for your type.

basically, changes this: https://github.com/couchbaselabs/elasticsearch-transport-couchbase/blob/master/src/main/resources/couchbase_template.json


(Vatsal Patel) #5

Thank you very much for your advice. i will keep in mind for code formating.


(Vatsal Patel) #6
 I have made below changes, Is it ok or i miss something?.Thank you in advance.

   PUT _template/couchbae
     {
        "template" : "*",
        "order" : 10,
        "mappings" : {
            "couchbaseCheckpoint" : {
                "_source" : {
                    "includes" : ["doc.*"]
                },
                "dynamic_templates": [
                    {
                        "store_no_index": {
                            "match": "*",
                            "mapping": {
                                "store" : "no",
                                "index" : "no",
                                "include_in_all" : false
                            }
                        }
                    }
                ]
            },
            "couchbaseDocument":{
            "properties": {
                   "location": {
                       "type": "geo_point"
                         }
                   }
            },
            "_default_" : {
                "_source" : {
                    "includes" : ["meta.*"]
                },
                "properties" : {
                    "meta" : {
                        "type" : "object",
                        "include_in_all" : false
                    }
                }
            }
        }
    }

(David Pilato) #7

It looks good.


(Vatsal Patel) #8

Hi, great it works..thank you


(system) #9