# Elasticsearch 2.0 geo distance search not working with location array

**URL:** <https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236>\
**Category:** Elasticsearch\
**Created:** [January 12, 2018, 7:48am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236 "2018-01-12T07:48:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![soumya.plavaga1](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@soumya.plavaga1](https://discuss.elastic.co/u/soumya.plavaga1)\
**Post date:** [January 12, 2018, 7:48am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236/1 "2018-01-12T07:48:15Z")

</div>

I am facing an issue with geo\_distance query in case of multiple locations within a single document. While filtering, it is always considering the first one in the list and ignoring the rest of the locations within the list. So if the first location does not match, the document is not appearing in the search result. Here is my example:

ES version: 2.0

Index:

```
 {
    "locations" : 
     {
        "type" : "geo_point"
     }
 }

```

Document:

`{"locations" : [{"lat": 12.9306989,"lon": 77.6870448}, {"lat": 12.9133638,"lon": 77.6870448}]}`

Search DSL:

```
{

"query": {
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_distance": {
                    "distance": "1km",
                    "locations": {"lat" : 12.9165699, "lon" : 77.6393489}
                }
            }
        }
    }

}

```

But the document is not coming in search result even the second location is within 1 km radius of the query 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:** [January 12, 2018, 8:16am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236/2 "2018-01-12T08:16:35Z")

</div>

I think your example is may be incorrect.

I tried with this:

```auto
DELETE test
PUT test
{
  "mappings": {
    "doc": {
      "properties": {
        "locations": {
          "type": "geo_point"
        }
      }
    }
  }
}
PUT test/doc/1
{
  "locations": [
    {
      "lat": 13.9306989,
      "lon": 78.6870448
    },
    {
      "lat": 12.9133638,
      "lon": 77.6870448
    }
  ]
}
GET test/_search
{
  "query": {
    "bool": {
      "filter": {
        "geo_distance": {
          "distance": "1km",
          "locations": {
            "lat": 12.9133638,
            "lon": 77.6870448
          }
        }
      }
    }
  }
}
GET test/_search
{
  "query": {
    "bool": {
      "filter": {
        "geo_distance": {
          "distance": "1km",
          "locations": {
            "lat": 13.9306989,
            "lon": 78.6870448
          }
        }
      }
    }
  }
}

```

This is giving expected results:

```auto
# GET test/_search
{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0,
    "hits": [
      {
        "_index": "test",
        "_type": "doc",
        "_id": "1",
        "_score": 0,
        "_source": {
          "locations": [
            {
              "lat": 13.9306989,
              "lon": 78.6870448
            },
            {
              "lat": 12.9133638,
              "lon": 77.6870448
            }
          ]
        }
      }
    ]
  }
}

# GET test/_search
{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0,
    "hits": [
      {
        "_index": "test",
        "_type": "doc",
        "_id": "1",
        "_score": 0,
        "_source": {
          "locations": [
            {
              "lat": 13.9306989,
              "lon": 78.6870448
            },
            {
              "lat": 12.9133638,
              "lon": 77.6870448
            }
          ]
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![soumya.plavaga1](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@soumya.plavaga1](https://discuss.elastic.co/u/soumya.plavaga1)\
**Post date:** [January 12, 2018, 9:58am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236/3 "2018-01-12T09:58:03Z")

</div>

Can you please try to execute using CURL command? I am getting empty results for the same.

```
curl -XGET 'localhost:9200/test/_search?pretty' -H 'Content-Type: application/json' -d'
{

"query": {
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_distance": {
                    "distance": "1km",
                    "locations": {"lat" : 12.9165699, "lon" : 77.6393489}
                }
            }
        }
    }

}'
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : []
  }
}
```

---

<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:** [January 12, 2018, 10:11am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236/4 "2018-01-12T10:11:05Z")

</div>

May be your point is not within 1km?

---

<div class="post-metadata">

**Author:** ![soumya.plavaga1](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@soumya.plavaga1](https://discuss.elastic.co/u/soumya.plavaga1)\
**Post date:** [January 12, 2018, 10:14am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236/5 "2018-01-12T10:14:31Z")

</div>

One location {"lat": 12.9133638,"lon": 77.6870448} is within 1km from the given location, but another one is more than one.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 12, 2018, 10:19am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236/6 "2018-01-12T10:19:01Z")

</div>

> [@soumya.plavaga1](#):
>
> "lon" : 77.6393489

You longitude starts 77.6 **3** while the example David provided and the data stored starts 77.6 **8** , so it is possible your point is not within 1km.

---

<div class="post-metadata">

**Author:** ![soumya.plavaga1](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@soumya.plavaga1](https://discuss.elastic.co/u/soumya.plavaga1)\
**Post date:** [January 12, 2018, 10:39am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236/7 "2018-01-12T10:39:24Z")

</div>

Yes. It was my bad data 😬 Sorry for the wrong alarm.

---

<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:** [February 9, 2018, 10:39am UTC](https://discuss.elastic.co/t/elasticsearch-2-0-geo-distance-search-not-working-with-location-array/115236/8 "2018-02-09T10:39:31Z")

</div>

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