I’m getting my feet wet trying to do geo spatial searches directly on the server
I have looked through some documentation and a couple of blogs/tutorials that show how to do this. However, my data structure is slightly different and when searching I don’t seem to get it right.
First, my data structure is either a polygon (e.g. a lake) or a poly line (e.g. a stream), i.e. an array of points. It’s all about fishing and where you fished, hence the names and this structure
So here is a snippet showing the data that I want to reach in:
{
"key": "8642",
"name": "The lake",
"points": [
{
"lat": 55.5747937187,
"lon": 11.2856648546
},
{
"lat": 55.5930342762,
"lon": 11.2790527292
},
:
:
{
"lat": 55.5566764979,
"lon": 11.3007332022
}
],
"type": "Lake"
}
When searching I will have the location specified by the user (i.e. a lat/lon point). So now I want to find out if this point is inside (or perhaps just close to) a lake or near a stream (poly line).
I have created a FTS index:
And then I have tried to search using PostMan and posting a request with this content (adapted from one of the examples in the blogs):
{
"from": 0,
"size": 2,
"fields": [
"points"
],
"query": {
"location": {
"lon": -55.6,
"lat": 11.33
},
"distance": "1mi",
"field": "points"
},
"sort": [
{
"by": "geo_distance",
"field": "points",
"unit": "mi",
"location": {
"lon": -55.6,
"lat": 11.33
}
}
]
}
But this is what I get back:
{
"status": {
"total": 6,
"failed": 0,
"successful": 6
},
"request": {
"query": {
"location": [
55.58,
11.28
],
"distance": "1mi",
"field": "points"
},
"size": 2,
"from": 0,
"highlight": null,
"fields": [
"points"
],
"facets": null,
"explain": false,
"sort": [
{
"by": "geo_distance",
"field": "points",
"location": {
"lat": 11.28,
"lon": 55.58
},
"unit": "mi"
}
],
"includeLocations": false
},
"hits": [],
"total_hits": 0,
"max_score": 0,
"took": 389578,
"facets": null
}
I would believe that the point should be less than a mile off the lake (or a nearby stream) so I’m sure this may have to do with the data structure that differs from the samples I have found.
Any ideas would be much appreciated
Thanks in advance.
/John