# 回复: really bad post\_filter performance

**URL:** https://discuss.elastic.co/t/really-bad-post-filter-performance/16730
**Category:** Elasticsearch
**Created:** [March 31, 2014, 11:47pm UTC](https://discuss.elastic.co/t/really-bad-post-filter-performance/16730 "2014-03-31T23:47:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![spancer\_ray](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spancer_ray/32/76303_2.png) [@spancer\_ray](https://discuss.elastic.co/u/spancer_ray)
#### Post date: [March 31, 2014, 11:47pm UTC](https://discuss.elastic.co/t/really-bad-post-filter-performance/16730/1 "2014-03-31T23:47:01Z")

</div>

Too many shards may result in querying performance.

daveey [daveey@gmail.com](mailto:daveey@gmail.com)编写：

> I just upgraded to ES 1.0.1 from ES 0.9.2 and am seeing huge performance problems.
> 
> I traced them to what I think is the post\_filter.
> 
> Here is the query that we used to run against ES 0.9.2
> 
> {  
> filter": {
> 
> "and": [
> 
> ```
> {
> 
> "terms": {
> 
> "index_ids": [
> 
> 2134616789944
> 
> ]
> 
> }
> 
> },
> 
> {
> 
> "or": [
> 
> {
> 
> "term": {
> 
> "trashed_at": 0
> 
> }
> 
> },
> 
> {
> 
> "not": {
> 
> "exists": {
> 
> "field": "trashed_at"
> 
> }
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> ]
> 
> }
> 
> }
> 
> This used to take the 0.9 cluster about 150ms to execute
> 
> The same query takes about 2.5s for the 1.0 cluster.
> 
> I rewrote it to conform to my understanding of the changes in 1.0, using a filtered query, however, that didn't help.
> 
> I then tried to figure out which parts were slow. I now have the following query
> 
> {  
> "query": {
> 
> "filtered": {
> 
> ```
> "query": {
> 
> "match_all": {}
> 
> },
> 
> "filter": {
> 
> "terms": {
> 
> "index_ids": [
> 
> 2134616789944
> 
> ]}
> 
> }
> 
> ```
> 
> }
> 
> },
> 
> "post\_filter": {
> 
> "or": [
> 
> ```
> {"term": {"trashed_at": 0}},
> 
> {"not": {"exists": {"field": "trashed_at"}}}
> 
> ]}
> 
> ```
> 
> }
> 
> It takes 2.5 s and returns 34 hits. However, removing the "post\_filter" clause:
> 
> {  
> "query": {
> 
> "filtered": {
> 
> ```
> "query": {
> 
> "match_all": {}
> 
> },
> 
> "filter": {
> 
> "terms": {
> 
> "index_ids": [
> 
> 2134616789944
> 
> ]
> 
> }
> 
> }
> 
> ```
> 
> }
> 
> }
> 
> }
> 
> Makes it take 50ms and return 34 results.
> 
> My conclusion is that it's taking 2.5 seconds to filter 34 results, and that's confusing.
> 
> The cluster uses 3 machines, 50 shards, 2 replicas per shard. This means that each machine has the entire copy of the index. We use the ?routing= parameter, and are always hitting a single shard for the query.
> 
> Help?
> 
> --  
> 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/cd5b6bb1-7fce-4688-84cb-4ec6d0db8f93%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cd5b6bb1-7fce-4688-84cb-4ec6d0db8f93%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/73fhfrw850xcj5nhwiuwk1o8.1396309621505%40email.android.com](https://groups.google.com/d/msgid/elasticsearch/73fhfrw850xcj5nhwiuwk1o8.1396309621505%40email.android.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)
#### Post date: [April 1, 2014, 3:14pm UTC](https://discuss.elastic.co/t/really-bad-post-filter-performance/16730/2 "2014-04-01T15:14:40Z")

</div>

I'd probably just collapse everything into a filtered query. Something like  
this:

{  
"query": {  
"filtered": {  
"filter": {  
"bool": {  
"must": [  
{  
"terms": {  
"index\_ids": ["2134616789944"]  
}  
}  
],  
"should": [  
{  
"terms": {  
"trashed\_at": "0"  
}  
},  
{  
"not": {  
"exists": {  
"field": "trashed\_at"  
}  
}  
}  
]  
}  
}  
}  
}  
}

--  
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/0845cbee-26bb-43be-9318-7a36a08e6504%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0845cbee-26bb-43be-9318-7a36a08e6504%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:39am UTC](https://discuss.elastic.co/t/really-bad-post-filter-performance/16730/3 "2017-07-06T01:39:00Z")

</div>


