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