# Dynamic passing latitude longitude is possible

**URL:** https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605
**Category:** Elasticsearch
**Created:** [May 17, 2019, 2:05pm UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605 "2019-05-17T14:05:35Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![elk3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elk3/32/46184_2.png) [@elk3](https://discuss.elastic.co/u/elk3)
#### Post date: [May 17, 2019, 2:05pm UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/1 "2019-05-17T14:05:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 17, 2019, 2:34pm UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/2 "2019-05-17T14:34:52Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) 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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

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?

---

<div class="post-metadata">

### Author: ![elk3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elk3/32/46184_2.png) [@elk3](https://discuss.elastic.co/u/elk3)
#### Post date: [May 20, 2019, 5:12am UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/3 "2019-05-20T05:12:42Z")

</div>

```
`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

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 20, 2019, 5:38am UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/4 "2019-05-20T05:38:36Z")

</div>

May be this could help? [https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-geo-shape-query.html#\_pre\_indexed\_shape](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.

---

<div class="post-metadata">

### Author: ![elk3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elk3/32/46184_2.png) [@elk3](https://discuss.elastic.co/u/elk3)
#### Post date: [May 20, 2019, 11:16am UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/5 "2019-05-20T11:16:22Z")

</div>

```
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

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 20, 2019, 11:32am UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/6 "2019-05-20T11:32:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![elk3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elk3/32/46184_2.png) [@elk3](https://discuss.elastic.co/u/elk3)
#### Post date: [May 20, 2019, 11:37am UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/7 "2019-05-20T11:37:51Z")

</div>

thanks for your reply

---

<div class="post-metadata">

### Author: ![elk3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elk3/32/46184_2.png) [@elk3](https://discuss.elastic.co/u/elk3)
#### Post date: [May 20, 2019, 11:50am UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/8 "2019-05-20T11:50:10Z")

</div>

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 )

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 20, 2019, 12:03pm UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/9 "2019-05-20T12:03:34Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![elk3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elk3/32/46184_2.png) [@elk3](https://discuss.elastic.co/u/elk3)
#### Post date: [May 20, 2019, 12:25pm UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/10 "2019-05-20T12:25:05Z")

</div>

![Capture](https://us1.discourse-cdn.com/elastic/original/3X/3/e/3ea7b08ac3b51f56495afbf90a69ef11e4c914b8.png)  
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
              }
            
       }
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 17, 2019, 12:25pm UTC](https://discuss.elastic.co/t/dynamic-passing-latitude-longitude-is-possible/181605/11 "2019-06-17T12:25:08Z")

</div>

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