Dynamic passing latitude longitude is possible

(Siva) #1

GET /schoolkpi/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter": {
"geo_distance": {
"distance": "1km",
"distance_type": "plane",
"location": {
"lat":40.715,
"lon":-73.988
}
}

  }
}

}
}

here i am passing latitude ,longitude static but i want latitude ,longitude to be dynamically value should comes in dynamic

(David Pilato) #2

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

What do you mean by dynamic?

(Siva) #3
`GET /schoolkpi/_search

{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter": {
"geo_distance": {
"distance": "1km",
"distance_type": "plane",
"location": {
"lat":40.715,
"lon":-73.988
}
}

}
}
}
}`

here my requirement is i want to filter school distance based on nearby location ,where latitude,longitude value should comes dynamically .........i.e is i choose three school in dropedown it will show nearby school based on latitude,longitude but value should comes dynamically

(David Pilato) #4

May be this could help? https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-geo-shape-query.html#_pre_indexed_shape

But, I think you have somewhere the lat/lon coordinates for each school. So it might be easier to just use a bool query with multiple match queries within should clauses and then sort by distance may be.

A full reproduction script could help to understand better may be.

(Siva) #5
GET /my_locations/_search {
"query": {
    "bool" : {
        "must" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "200km",
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}

i want latitude longitude column should be dynamic i.e like fielld:location

(David Pilato) #6

If I understand correctly what you want I'm afraid you can't do that.

(Siva) #7

thanks for your reply

(Siva) #8

sorry to ask again , i having 10 schools list each list contain latitude,longitude separately requirement if i choose one school means nearest two school want appear ,there is any possible,(i don't want latitude ,longitude to be filled by statically )

(David Pilato) #9

I'm not sure to understand without a concrete example.

Anyway, if you want within a dataset find which are the 2 closest schools, that's not possible I'm afraid. Unless someone else has an idea.

(Siva) #10

Capture
here i shown is database containing school latitude longitude value my requirement is if choose three school first one is current(latitude,longitude want to show ) school,remaining based on dropedown (value) it is possible

   POST locationskpi/_search
{
  "size": 0,
  "query": {
    "bool": {
      "filter": []
    }
  },
  "aggs": {
    "groupby_id": {
      "terms": {
        "field": "sch_id",
        "size": 9999,
        "order": {
          "_key": "asc"
        }
      },
      "aggs": {
        "query": {
          "filter": {
            "geo_distance": {
              "distance": "100km",
              "location": {
                "lat": 30.1624 ,\*(i want like this "lat":"latitude" )i want value to stored in variable*/
                "lon": -81.7447
              }
            
       }
          }
        }
      }
    }
  }
}