# Geo\_shape filter in post\_filter

**URL:** <https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748>\
**Category:** Elasticsearch\
**Created:** [February 12, 2014, 7:11am UTC](https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748 "2014-02-12T07:11:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HeonKyu\_Park](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@HeonKyu\_Park](https://discuss.elastic.co/u/HeonKyu_Park)\
**Post date:** [February 12, 2014, 7:11am UTC](https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748/1 "2014-02-12T07:11:06Z")

</div>

I have 2 types of document as below.

- _poi_: 4 millions, it has a point(lon, lat) field
- _region_: it has a polygon field

I'd like to search POI documents in a certain region by using geo\_shape  
filter.

So I made query as below.

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
}  
, "filter": {  
"and": [  
{"term": {"properties.category1":"2"}}  
, {"term": {"properties.category2":"1"}}  
, {"term": {"properties.category3":"1"}}  
, {"prefix": {"title":"xxx"}}  
]  
}  
}  
}  
, "post\_filter": {  
"geo\_shape": {  
"geometry": {  
"indexed\_shape": {  
"id": "21000",  
"type": "region",  
"index": "test",  
"shape\_field\_name": "geometry"  
}  
}  
}  
}  
}

The count of POI that's title contains 'xxx' is\* only 4.\*

But the response time of this query was _20 seconds_.

so I tested this query without the geo\_shape and post\_filter.

{  
"query": {

```
  "filtered": {
    "query": {
      "match_all": {}
    }
    , "filter": {
      "and": [ 
        {"term": {"properties.category1":"2"}}
        , {"term": {"properties.category2":"1"}}
        , {"term": {"properties.category3":"1"}}
        , {"prefix": {"title":"xxx"}} 
      ]
    }
  }
}

```

}

Result count of this query was _only 4_ and It took only _10 ms._

I though that the number of POI documents that are applied to geo\_shape  
filter is only 4 by using post\_filter.

Why post\_filter + geo\_shape filters are so slow?

Did I use the post\_filter + geo\_shape query correctlly?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6f578e25-beef-4c11-a913-605834fe4dae%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6f578e25-beef-4c11-a913-605834fe4dae%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 12, 2014, 4:38pm UTC](https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748/2 "2014-02-12T16:38:51Z")

</div>

I'm very curious, does this query make any difference in terms of speed  
(might need to run this more than once)?

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"and": [  
{  
"bool": {  
"must": [  
{  
"term": {  
"properties.category1": "2"  
}  
},  
{  
"term": {  
"properties.category2": "1"  
}  
},  
{  
"term": {  
"properties.category3": "1"  
}  
},  
{  
"prefix": {  
"title": "xxx"  
}  
}  
]  
}  
},  
{  
"geo\_shape": {  
"geometry": {  
"indexed\_shape": {  
"id": "21000",  
"type": "region",  
"index": "test",  
"shape\_field\_name": "geometry"  
}  
}  
}  
}  
]  
}  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/01bec9b4-bd20-422e-a5ec-251ccd442d7c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/01bec9b4-bd20-422e-a5ec-251ccd442d7c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![HeonKyu\_Park](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@HeonKyu\_Park](https://discuss.elastic.co/u/HeonKyu_Park)\
**Post date:** [February 13, 2014, 3:39am UTC](https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748/3 "2014-02-13T03:39:45Z")

</div>

Thanks for your response. Binh.

No difference. It still took 20 seconds.

There was no improvement on speed.

2014년 2월 13일 목요일 오전 1시 38분 51초 UTC+9, Binh Ly 님의 말:

> I'm very curious, does this query make any difference in terms of speed  
> (might need to run this more than once)?
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "and": [  
> {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "properties.category1": "2"  
> }  
> },  
> {  
> "term": {  
> "properties.category2": "1"  
> }  
> },  
> {  
> "term": {  
> "properties.category3": "1"  
> }  
> },  
> {  
> "prefix": {  
> "title": "xxx"  
> }  
> }  
> ]  
> }  
> },  
> {  
> "geo\_shape": {  
> "geometry": {  
> "indexed\_shape": {  
> "id": "21000",  
> "type": "region",  
> "index": "test",  
> "shape\_field\_name": "geometry"  
> }  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e3ae3dad-1c62-443e-800d-c45021e0f6ac%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e3ae3dad-1c62-443e-800d-c45021e0f6ac%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![chilling](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@chilling](https://discuss.elastic.co/u/chilling)\
**Post date:** [February 14, 2014, 2:47am UTC](https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748/4 "2014-02-14T02:47:53Z")

</div>

hi HeonKyu,

may I ask, what your polygons look like. Do they contain wholes? How many  
points describing your polygons? Maybe the geo\_polygon\_filter is an  
alternative for you.

Thanks,  
Florian

On Thursday, February 13, 2014 12:39:45 PM UTC+9, HeonKyu Park wrote:

> Thanks for your response. Binh.
> 
> No difference. It still took 20 seconds.
> 
> There was no improvement on speed.
> 
> 2014년 2월 13일 목요일 오전 1시 38분 51초 UTC+9, Binh Ly 님의 말:
> 
> > I'm very curious, does this query make any difference in terms of speed  
> > (might need to run this more than once)?
> > 
> > {  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "filter": {  
> > "and": [  
> > {  
> > "bool": {  
> > "must": [  
> > {  
> > "term": {  
> > "properties.category1": "2"  
> > }  
> > },  
> > {  
> > "term": {  
> > "properties.category2": "1"  
> > }  
> > },  
> > {  
> > "term": {  
> > "properties.category3": "1"  
> > }  
> > },  
> > {  
> > "prefix": {  
> > "title": "xxx"  
> > }  
> > }  
> > ]  
> > }  
> > },  
> > {  
> > "geo\_shape": {  
> > "geometry": {  
> > "indexed\_shape": {  
> > "id": "21000",  
> > "type": "region",  
> > "index": "test",  
> > "shape\_field\_name": "geometry"  
> > }  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f088909f-feff-413d-bfee-3175ae7722ad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f088909f-feff-413d-bfee-3175ae7722ad%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![HeonKyu\_Park](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@HeonKyu\_Park](https://discuss.elastic.co/u/HeonKyu_Park)\
**Post date:** [February 14, 2014, 5:12am UTC](https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748/5 "2014-02-14T05:12:29Z")

</div>

Hi Forian,

The polygon consists of 2,000 points and it's not multi-polygon. (no  
interior-ring, no exterior-ring).

and I will test geo polygon filter and let you know soon.

but I don't want to read the polygon data to pass to geo polygon filter  
because it's too big.That's why I use geoshape filter.

Thanks

2014년 2월 14일 금요일 오전 11시 47분 53초 UTC+9, Florian Schilling 님의 말:

> hi HeonKyu,
> 
> may I ask, what your polygons look like. Do they contain wholes? How many  
> points describing your polygons? Maybe the geo\_polygon\_filter is an  
> alternative for you.
> 
> Thanks,  
> Florian
> 
> On Thursday, February 13, 2014 12:39:45 PM UTC+9, HeonKyu Park wrote:
> 
> > Thanks for your response. Binh.
> > 
> > No difference. It still took 20 seconds.
> > 
> > There was no improvement on speed.
> > 
> > 2014년 2월 13일 목요일 오전 1시 38분 51초 UTC+9, Binh Ly 님의 말:
> > 
> > > I'm very curious, does this query make any difference in terms of speed  
> > > (might need to run this more than once)?
> > > 
> > > {  
> > > "query": {  
> > > "filtered": {  
> > > "query": {  
> > > "match\_all": {}  
> > > },  
> > > "filter": {  
> > > "and": [  
> > > {  
> > > "bool": {  
> > > "must": [  
> > > {  
> > > "term": {  
> > > "properties.category1": "2"  
> > > }  
> > > },  
> > > {  
> > > "term": {  
> > > "properties.category2": "1"  
> > > }  
> > > },  
> > > {  
> > > "term": {  
> > > "properties.category3": "1"  
> > > }  
> > > },  
> > > {  
> > > "prefix": {  
> > > "title": "xxx"  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > },  
> > > {  
> > > "geo\_shape": {  
> > > "geometry": {  
> > > "indexed\_shape": {  
> > > "id": "21000",  
> > > "type": "region",  
> > > "index": "test",  
> > > "shape\_field\_name": "geometry"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/980999f6-b06a-4d96-8b17-5c25d585ffc2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/980999f6-b06a-4d96-8b17-5c25d585ffc2%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![chilling](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@chilling](https://discuss.elastic.co/u/chilling)\
**Post date:** [February 14, 2014, 7:46am UTC](https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748/6 "2014-02-14T07:46:15Z")

</div>

Hi HeonKyu,

I also prefer the geo\_shape filter for huge polygons. I'm going to improve  
the code there.

Thanks,  
Florian

On Friday, February 14, 2014 2:12:29 PM UTC+9, HeonKyu Park wrote:

> Hi Forian,
> 
> The polygon consists of 2,000 points and it's not multi-polygon. (no  
> interior-ring, no exterior-ring).
> 
> and I will test geo polygon filter and let you know soon.
> 
> but I don't want to read the polygon data to pass to geo polygon filter  
> because it's too big.That's why I use geoshape filter.
> 
> Thanks
> 
> 2014년 2월 14일 금요일 오전 11시 47분 53초 UTC+9, Florian Schilling 님의 말:
> 
> > hi HeonKyu,
> > 
> > may I ask, what your polygons look like. Do they contain wholes? How many  
> > points describing your polygons? Maybe the geo\_polygon\_filter is an  
> > alternative for you.
> > 
> > Thanks,  
> > Florian
> > 
> > On Thursday, February 13, 2014 12:39:45 PM UTC+9, HeonKyu Park wrote:
> > 
> > > Thanks for your response. Binh.
> > > 
> > > No difference. It still took 20 seconds.
> > > 
> > > There was no improvement on speed.
> > > 
> > > 2014년 2월 13일 목요일 오전 1시 38분 51초 UTC+9, Binh Ly 님의 말:
> > > 
> > > > I'm very curious, does this query make any difference in terms of speed  
> > > > (might need to run this more than once)?
> > > > 
> > > > {  
> > > > "query": {  
> > > > "filtered": {  
> > > > "query": {  
> > > > "match\_all": {}  
> > > > },  
> > > > "filter": {  
> > > > "and": [  
> > > > {  
> > > > "bool": {  
> > > > "must": [  
> > > > {  
> > > > "term": {  
> > > > "properties.category1": "2"  
> > > > }  
> > > > },  
> > > > {  
> > > > "term": {  
> > > > "properties.category2": "1"  
> > > > }  
> > > > },  
> > > > {  
> > > > "term": {  
> > > > "properties.category3": "1"  
> > > > }  
> > > > },  
> > > > {  
> > > > "prefix": {  
> > > > "title": "xxx"  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > },  
> > > > {  
> > > > "geo\_shape": {  
> > > > "geometry": {  
> > > > "indexed\_shape": {  
> > > > "id": "21000",  
> > > > "type": "region",  
> > > > "index": "test",  
> > > > "shape\_field\_name": "geometry"  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }  
> > > > }  
> > > > }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d4139d74-3f1a-4f39-b332-3644aff58dad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d4139d74-3f1a-4f39-b332-3644aff58dad%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 1:50am UTC](https://discuss.elastic.co/t/geo-shape-filter-in-post-filter/15748/7 "2017-07-06T01:50:17Z")

</div>


