# Filter facet results to exclude not wanted terms

**URL:** <https://discuss.elastic.co/t/filter-facet-results-to-exclude-not-wanted-terms/12567>\
**Category:** Elasticsearch\
**Created:** [June 27, 2013, 3:46pm UTC](https://discuss.elastic.co/t/filter-facet-results-to-exclude-not-wanted-terms/12567 "2013-06-27T15:46:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sofrit0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sofrit0/32/1876_2.png) [@Sofrit0](https://discuss.elastic.co/u/Sofrit0)\
**Post date:** [June 27, 2013, 3:46pm UTC](https://discuss.elastic.co/t/filter-facet-results-to-exclude-not-wanted-terms/12567/1 "2013-06-27T15:46:30Z")

</div>

I have a facet to count shingles, now I want to filter the facet results to  
exclude shingles given a simple rule I'm expressing as a regex using script:

{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"blah": {  
"terms": {  
"field": "text.shingles",  
"size": "400",  
"script": {

```
                "script": "term.match(new RegExp(regex, 'i')) ? false : 

```

true",  
"lang": "js",  
"params": {  
"regex":  
"(.)(1|2|3|a|en|yo|tu|ti|tus|ellos|nos|su|sus|por|en|de|del|el|le|la|lo|las|los|les|con|no|y|t|que|me|para|da|san|mi|un|una|te|es|esa|ese|esos|esta|este|estos|estas|ya|se|como|to|be|the|si|ya)"  
}  
}  
}  
}  
}  
}

This works as it does remove those shingles that match the regex, however  
it takes a lot of time.

What's the smart way of achieving the same?

Thanks

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [June 27, 2013, 6:21pm UTC](https://discuss.elastic.co/t/filter-facet-results-to-exclude-not-wanted-terms/12567/2 "2013-06-27T18:21:58Z")

</div>

Why not use terms facet exclude parameter since you do Not seem to have any wildcard in your regexp or facet\_filter if you need more complex logic?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Sofrit0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sofrit0/32/1876_2.png) [@Sofrit0](https://discuss.elastic.co/u/Sofrit0)\
**Post date:** [June 27, 2013, 8:04pm UTC](https://discuss.elastic.co/t/filter-facet-results-to-exclude-not-wanted-terms/12567/3 "2013-06-27T20:04:35Z")

</div>

There is a wildcard. Notice the (.) at the beginning of the regex. Since I  
want to exclude 2-fold shingles, the regex is matching only the second  
term. I had prefered using (\s) instead of (.) but it does not work.

On Thursday, June 27, 2013 2:21:58 PM UTC-4, AlexR wrote:

> Why not use terms facet exclude parameter since you do Not seem to have  
> any wildcard in your regexp or facet\_filter if you need more complex logic?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 28, 2013, 7:22am UTC](https://discuss.elastic.co/t/filter-facet-results-to-exclude-not-wanted-terms/12567/4 "2013-06-28T07:22:19Z")

</div>

Hey,

faceting on an analyzed (like a shingle) field will increase the chances of  
running out of memory at some time, because your are basically un-inverting  
the lucene inverted index and put it into memory. Maybe there is another  
solution for your problem, if you can tell us a bit more about what you try  
to achieve (in a broader context).

--Alex

On Thu, Jun 27, 2013 at 10:04 PM, Santiago Gaviria [sgaviria@gmail.com](mailto:sgaviria@gmail.com)wrote:

> There is a wildcard. Notice the (.) at the beginning of the regex. Since I  
> want to exclude 2-fold shingles, the regex is matching only the second  
> term. I had prefered using (\s) instead of (.) but it does not work.
> 
> On Thursday, June 27, 2013 2:21:58 PM UTC-4, AlexR wrote:
> 
> > Why not use terms facet exclude parameter since you do Not seem to have  
> > any wildcard in your regexp or facet\_filter if you need more complex logic?
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
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, 2:29am UTC](https://discuss.elastic.co/t/filter-facet-results-to-exclude-not-wanted-terms/12567/5 "2017-07-06T02:29:05Z")

</div>


