# Search by any location

**URL:** <https://discuss.elastic.co/t/search-by-any-location/173042>\
**Category:** Elasticsearch\
**Created:** [March 19, 2019, 7:22pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042 "2019-03-19T19:22:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Michelsongs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_michelsongs/32/19766_2.png) [@Miguel\_Michelsongs](https://discuss.elastic.co/u/Miguel_Michelsongs)\
**Post date:** [March 19, 2019, 7:22pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/1 "2019-03-19T19:22:43Z")

</div>

Hi I have a mapping with geopoints, and I would like to query all the items that have a location. is there any way to search results that have geopoint and skip items without geopoints ?

thanks

---

<div class="post-metadata">

**Author:** ![Miguel\_Michelsongs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_michelsongs/32/19766_2.png) [@Miguel\_Michelsongs](https://discuss.elastic.co/u/Miguel_Michelsongs)\
**Post date:** [March 19, 2019, 8:12pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/2 "2019-03-19T20:12:21Z")

</div>

I don't know if this counts as a real solution , but I'm quering  
`"geo_distance":{"location":{"lat":0,"lon":0},"distance":"1000000000000000mi"}`

I suppose that would be a better alternatives to tackle this

---

<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:** [March 19, 2019, 8:35pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/3 "2019-03-19T20:35:57Z")

</div>

Can you just check if the field location.lat actually exists with the `exist` query?

---

<div class="post-metadata">

**Author:** ![Miguel\_Michelsongs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_michelsongs/32/19766_2.png) [@Miguel\_Michelsongs](https://discuss.elastic.co/u/Miguel_Michelsongs)\
**Post date:** [March 20, 2019, 2:11pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/4 "2019-03-20T14:11:00Z")

</div>

Hi , I've tried these two queries, both return empty results.

`'{"query":{"exists":{"field":"location.accuracy"}}}'`  
=\>   
`'{"query":{"bool":{"must":[{"exists":{"field":"location.accuracy"}}]}}}'`  
=\>

---

<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:** [March 20, 2019, 2:32pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/5 "2019-03-20T14:32:40Z")

</div>

Is `accuracy` an existing field?  
What is your mapping?

---

<div class="post-metadata">

**Author:** ![Miguel\_Michelsongs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_michelsongs/32/19766_2.png) [@Miguel\_Michelsongs](https://discuss.elastic.co/u/Miguel_Michelsongs)\
**Post date:** [March 20, 2019, 2:40pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/6 "2019-03-20T14:40:20Z")

</div>

yes, I've also done the same query with lat / lng and got the same results

the location field mapping is a :

```
"location": {
"type": "geo_point"
},
```

---

<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:** [March 20, 2019, 3:27pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/7 "2019-03-20T15:27:42Z")

</div>

I don't see in this mapping any field named `location.accuracy`.

This example works well for me:

```auto
DELETE test
PUT test 
{
  "mappings": {
    "_doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}
PUT test/_doc/1
{
  "foo": "bar",
  "location": [0.0, 0.0]
}
PUT test/_doc/2
{
  "foo": "bar",
  "location": {
    "lat": 0.0,
    "lon": 0.0
  }
}
PUT test/_doc/3
{
  "foo": "bar"
}
GET test/_search
{
  "query": {
    "exists": {
      "field": "location"
    }
  }
}

```

It gives:

```auto
{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "foo" : "bar",
          "location" : {
            "lat" : 0.0,
            "lon" : 0.0
          }
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "foo" : "bar",
          "location" : [
            0.0,
            0.0
          ]
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![Miguel\_Michelsongs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_michelsongs/32/19766_2.png) [@Miguel\_Michelsongs](https://discuss.elastic.co/u/Miguel_Michelsongs)\
**Post date:** [March 20, 2019, 3:33pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/8 "2019-03-20T15:33:41Z")

</div>

Oh! I didn't try "location" only field, it just work!

thanks!

---

<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:** [April 17, 2019, 3:33pm UTC](https://discuss.elastic.co/t/search-by-any-location/173042/9 "2019-04-17T15:33:42Z")

</div>

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