# Problems with Post filter in 0.90.2; script filter and related question

**URL:** https://discuss.elastic.co/t/problems-with-post-filter-in-0-90-2-script-filter-and-related-question/18785
**Category:** Elasticsearch
**Created:** [July 22, 2014, 9:35am UTC](https://discuss.elastic.co/t/problems-with-post-filter-in-0-90-2-script-filter-and-related-question/18785 "2014-07-22T09:35:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Pramod\_N](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pramod_n/32/1384_2.png) [@Pramod\_N](https://discuss.elastic.co/u/Pramod_N)
#### Post date: [July 22, 2014, 9:35am UTC](https://discuss.elastic.co/t/problems-with-post-filter-in-0-90-2-script-filter-and-related-question/18785/1 "2014-07-22T09:35:10Z")

</div>

Hello,

I've been working on a problem where modelling the search filters as ES  
filters has almost become impossible.  
e.g: The incoming filter is generated by an application enforcing certain  
constraints on search. The filter itself is hierarchical and dynamic in  
nature depending on certain parameters. Think of it as a directory  
structure(ex. is completely different and over simplification, but comes  
very close in terms of representation)

aFilter = {  
"root": {  
"usr": {  
"elasticsearch": "present",  
"es-index-notification": "absent"  
},  
"system": {  
"elasticsearch": "present",  
"es-index-notification": "present",  
"attachment": "present"  
}  
}  
}

The filter predicate essentially involves traversing this structure breadth  
first (not a big and growing structure; space and time complexity would be  
reasonably constant) and match it with information in the indexed  
document(one field in particular)

Was thinking of using the ScriptFilter for the traversal. The other trouble  
is performance if this filter is applied along with search(large document  
set).

This is where the post\_filter made sense, in order to reduce the  
performance impact.

My question is two fold:

1. the documentation claims post\_filter is available as part of 0.90.x but  
its only available for versions after 0.90.8(was able to verify with that);  
am i missing something?

- I'm currently using 0.90.2(planning for an upgrade, have various other  
constraints, will probably happen in near future) and tried the example on  
the page  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/search-request-post-filter.html#search-request-post-filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/search-request-post-filter.html#search-request-post-filter)  
Parse Failure [No  
parser for element [post\_filter]]];
- Looks like the post\_filter parser is not available

1. is there any place where i can find info on the query order pre\_filter,  
query, post\_filter, pagination and sort etc?

Finally the problem statement in general - is there a non script way of  
achieving this in elasticsearch?

Apologies for the long email, any insight on this is appreciated.

Thank you,

Pramod N  
@machinelearner [https://twitter.com/machinelearner](https://twitter.com/machinelearner)

--

--  
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/CAGEoYnu7SiMPJUKLC0zABy10kpuUmEZUCZV3SCgfAwUUkUOZvA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGEoYnu7SiMPJUKLC0zABy10kpuUmEZUCZV3SCgfAwUUkUOZvA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [July 23, 2014, 2:39am UTC](https://discuss.elastic.co/t/problems-with-post-filter-in-0-90-2-script-filter-and-related-question/18785/2 "2014-07-23T02:39:28Z")

</div>

The post filter is not a addition in 0.90.8, just a renaming of a field  
that was ambiguous:

> <https://github.com/elastic/elasticsearch/issues/4119>
>
> Users tend to use the top-level \`filter\` param for general filtering, instead of… using a \`filtered\` query.
> 
> It should be renamed to \`post\_filter\` to dissuade users from using it unless they understand what it is for and \`filter\` should be deprecated.
> 
> The top level \`filter\` is still valid field for backwards compatibility, but it will removed in the future.

Pre filters are simply filtered queries. In most cases, you want to use the  
pre filters. Queries are expensive in Lucene since you have to score each  
document. Filters are the other hand are cheap since they are bitsets. If  
you filter out the documents beforehand, there is less to score. You only  
want to use post filters for expensive filters (geo, filters that  
cannot/shouldn't be cached) or when you want to calculate  
facets/aggregations on unfiltered documents. The post filter page has some  
more details:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

As far as your use case goes, some more details would help. Not just a  
sample document, but an example query and a result. I have never used the  
script filters, but in general, hierarchal data is difficult to manipulate.

Cheers,

Ivan

On Tue, Jul 22, 2014 at 2:35 AM, Pramod N [npramod05@gmail.com](mailto:npramod05@gmail.com) wrote:

> Hello,
> 
> I've been working on a problem where modelling the search filters as ES  
> filters has almost become impossible.  
> e.g: The incoming filter is generated by an application enforcing certain  
> constraints on search. The filter itself is hierarchical and dynamic in  
> nature depending on certain parameters. Think of it as a directory  
> structure(ex. is completely different and over simplification, but comes  
> very close in terms of representation)
> 
> aFilter = {  
> "root": {  
> "usr": {  
> "elasticsearch": "present",  
> "es-index-notification": "absent"  
> },  
> "system": {  
> "elasticsearch": "present",  
> "es-index-notification": "present",  
> "attachment": "present"  
> }  
> }  
> }
> 
> The filter predicate essentially involves traversing this structure  
> breadth first (not a big and growing structure; space and time complexity  
> would be reasonably constant) and match it with information in the indexed  
> document(one field in particular)
> 
> Was thinking of using the ScriptFilter for the traversal. The other  
> trouble is performance if this filter is applied along with search(large  
> document set).
> 
> This is where the post\_filter made sense, in order to reduce the  
> performance impact.
> 
> My question is two fold:
> 
> 1. the documentation claims post\_filter is available as part of 0.90.x but  
> its only available for versions after 0.90.8(was able to verify with that);  
> am i missing something?
> 
> - I'm currently using 0.90.2(planning for an upgrade, have various other  
> constraints, will probably happen in near future) and tried the example on  
> the page  
> [http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/search-request-post-filter.html#search-request-post-filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/search-request-post-filter.html#search-request-post-filter)  
> Parse Failure [No  
> parser for element [post\_filter]]];
> - Looks like the post\_filter parser is not available
> 
> 1. is there any place where i can find info on the query order pre\_filter,  
> query, post\_filter, pagination and sort etc?
> 
> Finally the problem statement in general - is there a non script way of  
> achieving this in elasticsearch?
> 
> Apologies for the long email, any insight on this is appreciated.
> 
> Thank you,
> 
> Pramod N  
> @machinelearner [https://twitter.com/machinelearner](https://twitter.com/machinelearner)
> 
> --
> 
> --  
> 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/CAGEoYnu7SiMPJUKLC0zABy10kpuUmEZUCZV3SCgfAwUUkUOZvA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGEoYnu7SiMPJUKLC0zABy10kpuUmEZUCZV3SCgfAwUUkUOZvA%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAGEoYnu7SiMPJUKLC0zABy10kpuUmEZUCZV3SCgfAwUUkUOZvA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGEoYnu7SiMPJUKLC0zABy10kpuUmEZUCZV3SCgfAwUUkUOZvA%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> 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/CALY%3DcQAMWTpQDz9sSqNp%2BNb0-oJtdY9Dmxr%2Bj2MxcyQXVT%3D24g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAMWTpQDz9sSqNp%2BNb0-oJtdY9Dmxr%2Bj2MxcyQXVT%3D24g%40mail.gmail.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:14am UTC](https://discuss.elastic.co/t/problems-with-post-filter-in-0-90-2-script-filter-and-related-question/18785/3 "2017-07-06T01:14:06Z")

</div>


