Erorr: "[query_shard_exception] failed to find geo_point field (in node js application)


(Muhammad Ali Tahir) #1

I'm working on node js (version 6.1.0 ) application and using elasticsearch (version 5.0.1) in it. But I'm having issues in geo_point query.
I'm doing mapping like this

client.indices.putMapping({
    index: 'newtesting',
    type: 'newtesting',
    body: {
        "mappings": {
            "location": {
                "properties": {
                    "pin": {
                        "properties": {
                            "location": {
                                "type": "geo_point"
                            }
                        }
                    }
                }
            }
        }
    }
});

and inserting data like this

client.index({
                index: 'newtesting',
                type: 'newtesting',
                body: {

                    "pin" : {
                        "location" : {
                            "lat" : 40.12,
                            "lon" : -71.34
                        }
                    }
                }
            },
            function (err, result, ElasticStatus) {
                if(err)
                    res.send("Unable to add Vendor Location" + err );
                else{
                    console.log("Location Stored "+result);
                    res.send(result);
                }


            });

and doing searching like this

client.search({
                index: 'newtesting',
                type: 'newtesting',
                body: {
                    "query": {
                        "bool" : {
                            "must" : {
                                "match_all" : { }
                            },
                            "filter" : {
                                "geo_distance" : {
                                    "distance" : "200km",
                                    "pin.location" : {
                                        "lat" : 40,
                                        "lon" : -70
                                    }
                                }
                            }
                        }
                    }
                }
            }, function (error, response)
            {
                if(error)
                    console.log("error occured " + error);
                else {
                    console.log(response.hits.hits[0]._source);
                    vendorArray.push(response.hits.hits[0]._source);
                    res.status(200).json(vendorArray);
                }
            });

I've tried many different formats, but I always get this same error, tried different versions as well, but same error
"[query_shard_exception] failed to find geo_point field [pin.location]"
Please help me if you have any idea about this


(Thiago Souza) #2

There are a few things wrong here. Your dealing with a type named location while calling newtesting everywhere. Here is what you need to fix:

  1. The putMapping should have "type": "location" and the body should be the object under properties.location
  2. The index request should have "type": "location".
  3. The search request should have "type": "location"

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.