# My problem about Geo-bounding box query indexed

**URL:** <https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597>\
**Category:** Elasticsearch\
**Created:** [March 18, 2021, 5:23am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597 "2021-03-18T05:23:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sakura1996](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@Sakura1996](https://discuss.elastic.co/u/Sakura1996)\
**Post date:** [March 18, 2021, 5:23am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/1 "2021-03-18T05:23:03Z")

</div>

Hi, I encountered 2 problems when following the doc, ES version is 7.9.

1. As the doc when use `type="indexed"` option in bounding box query, the geo-point type must have lat and lon indexed, but I want to know how to do it? (when I set `"lat_lon"=true` in mapping, will cause a error `"Mapping definition for [location] has unsupported parameters: [lat_lon : true]"`) 

2. I use this query :

```auto
{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "geo_bounding_box": {
          "pin.location": {
            "top_left": {
              "lat": 40.73,
              "lon": -74.1
            },
            "bottom_right": {
              "lat": 40.10,
              "lon": -71.12
            }
          },
          "type": "indexed"
        }
      }
    }
  }
}

```

to filter this data in ES:

```auto
{
                "_index": "my_locations",
                "_type": "_doc",
                "_id": "5",
                "_score": 0.0,
                "_source": {
                    "pin": {
                        "location": [
                            [
                                -71.34,
                                40.12
                            ],
                            [
                                -80,
                                86
                            ]
                        ]
                    }
                }
            }

```

As the doc ES `don't support multi locations per document field` when I use `type="indexed"` option in my query, but actually I got this unexpected data whose `location` field has 2 pair of geo-point. Is my understanding right? I 'm confused about this.

Thank you for help in advance!🙂

---

<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:** [March 18, 2021, 5:34am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/2 "2021-03-18T05:34:23Z")

</div>

I am not sure anyone will be able to help unless you describe the problems you faced well enough so someone can recreate the issues.

---

<div class="post-metadata">

**Author:** ![Sakura1996](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@Sakura1996](https://discuss.elastic.co/u/Sakura1996)\
**Post date:** [March 18, 2021, 6:46am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/4 "2021-03-18T06:46:54Z")

</div>

I described the 2 problems, could you pls help me solve it? thanks 🙂

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [March 18, 2021, 2:32pm UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/5 "2021-03-18T14:32:12Z")

</div>

I open the following issue:

> <https://github.com/elastic/elasticsearch/issues/70561>
>
> The following parameter is documented in the geo\_bounding\_box query:
> https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html#geo-bbox-type
> It seems that is coming from the implementation previous to the introduction of...

The documentation is stale and actually the parameter has no effect whatsoever in the results of the query. You can safely ignore it.

---

<div class="post-metadata">

**Author:** ![Sakura1996](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@Sakura1996](https://discuss.elastic.co/u/Sakura1996)\
**Post date:** [March 19, 2021, 2:59am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/6 "2021-03-19T02:59:07Z")

</div>

It seems recommend not to use this `type` parameter, right? But in my local test 500,000 data, I find if I use `type=indexed`, the bounding box query is faster.

| geo-query filter | performance(ms) | performance(ms) | performance(ms) |
| --- | --- | --- | --- |
| BoundingBoxQuery | 4,127 | 3,367 | 4,911 |
| BoundingBoxQueryIndexed | 21 | 14 | 26 |

Could you pls tell me why this happened? Does this parameter affect the query speed? 🙂 Thank you for help in advance!

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [March 19, 2021, 6:39am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/7 "2021-03-19T06:39:56Z")

</div>

Could you explain how did you get those numbers? It sounds to me that in one case the query is cached.

---

<div class="post-metadata">

**Author:** ![Sakura1996](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@Sakura1996](https://discuss.elastic.co/u/Sakura1996)\
**Post date:** [March 19, 2021, 8:36am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/8 "2021-03-19T08:36:12Z")

</div>

No,I think is not catched, because I tested a few times and calculate average value.

I have 500,000 data of a index in my local ES, and I use this 2 queryBuilder:

```java
GeoBoundingBoxQueryBuilder geo_bbox_qb = QueryBuilders.geoBoundingBoxQuery("location")
                .setCorners(40.99, -71,
                        40, -69);

GeoBoundingBoxQueryBuilder geo_bbox_qb = QueryBuilders.geoBoundingBoxQuery("location")
                .setCorners(40.99, -71,
                        40, -69).type("indexed");

```

This 2 query both can get 495,049 data, but for the `indexed` query, it was faster as above table shows.  
Could you pls explain that why you abandon the `type` parameter, after all it has a better performance through I tested.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [March 19, 2021, 10:49am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/9 "2021-03-19T10:49:59Z")

</div>

You are just running the query once? the first time it will run the query but the second time it will use the cache. Therefore the timing difference.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [March 19, 2021, 11:28am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/10 "2021-03-19T11:28:06Z")

</div>

You can check by yourself that when building the Lucene query, the type parameter is not used so in both cases you are running exactly the same query:

> <https://github.com/elastic/elasticsearch/blob/348e1ae47164a91685cee0a3c9efaf65f505a04f/server/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java#L307>

There is something not right in your methodology. You should use tools like [rally](https://esrally.readthedocs.io/en/stable/) to benchmark Elasticsearch.

Maybe you can try reversing the order you are executing your queries and see if the results are consistent?

---

<div class="post-metadata">

**Author:** ![Sakura1996](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@Sakura1996](https://discuss.elastic.co/u/Sakura1996)\
**Post date:** [March 24, 2021, 6:42am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/11 "2021-03-24T06:42:31Z")

</div>

Thank you for your answer! I reversed the query order then this 2 query have similar speed, you are right, before difference caused by cache.🙂

---

<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 21, 2021, 6:42am UTC](https://discuss.elastic.co/t/my-problem-about-geo-bounding-box-query-indexed/267597/12 "2021-04-21T06:42:55Z")

</div>

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