# Filter the facet terms?

**URL:** <https://discuss.elastic.co/t/filter-the-facet-terms/8825>\
**Category:** Elasticsearch\
**Created:** [August 23, 2012, 6:32am UTC](https://discuss.elastic.co/t/filter-the-facet-terms/8825 "2012-08-23T06:32:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Waddle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_waddle/32/2608_2.png) [@Mark\_Waddle](https://discuss.elastic.co/u/Mark_Waddle)\
**Post date:** [August 23, 2012, 6:32am UTC](https://discuss.elastic.co/t/filter-the-facet-terms/8825/1 "2012-08-23T06:32:52Z")

</div>

I have a field called abstract that has numerous words per document, as you  
can imagine. I would like to use this field as a dictionary of sorts for  
autocompletion of individual search terms. I have done some research on the  
autocomplete solutions out there and it seems that they all work for fields  
that have single or few terms per document, but not for my case where the  
number of terms per document can be in the hundreds.

I tried to do a wildcard on an edgengram field in combination with  
highlighting, but that just gives the top X docs that match that. So I will  
get 1,000s of docs that match "wireless", then 1,000s of docs that match  
"wired", etc. Not gonna work.

I also tried faceting on a tokenized field, but of course I get all of the  
popular terms in the facet as opposed to the terms that match my query. I  
tried the facet filter, but that only filters the docs that the facet  
matches against, still returning all of the most popular terms. I end up  
with facets like "a", "the", "from", "includes".

So I am thinking what would be ideal for my case is to be able to filter  
the facet _terms_ using a wildcard, as opposed to the docs. So far I have  
not discovered a way to do this. Is this possible with elasticsearch out of  
the box? Is there another, better solution for my problem?

Thanks for your help!  
Mark

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 23, 2012, 7:04am UTC](https://discuss.elastic.co/t/filter-the-facet-terms/8825/2 "2012-08-23T07:04:54Z")

</div>

Wildcard is not available as a filter.  
Wildcard is slow.

I would define my own analyzer for that field with edgengram tokenizer ([http://www.elasticsearch.org/guide/reference/index-modules/analysis/edgengram-tokenizer.html](http://www.elasticsearch.org/guide/reference/index-modules/analysis/edgengram-tokenizer.html)) and an english analyzer.  
Then, a Term facet on that field could give you the first 10 terms.

My 2 cents.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 23 août 2012 à 08:32, Mark Waddle [mark@markwaddle.com](mailto:mark@markwaddle.com) a écrit :

I have a field called abstract that has numerous words per document, as you can imagine. I would like to use this field as a dictionary of sorts for autocompletion of individual search terms. I have done some research on the autocomplete solutions out there and it seems that they all work for fields that have single or few terms per document, but not for my case where the number of terms per document can be in the hundreds.

I tried to do a wildcard on an edgengram field in combination with highlighting, but that just gives the top X docs that match that. So I will get 1,000s of docs that match "wireless", then 1,000s of docs that match "wired", etc. Not gonna work.

I also tried faceting on a tokenized field, but of course I get all of the popular terms in the facet as opposed to the terms that match my query. I tried the facet filter, but that only filters the docs that the facet matches against, still returning all of the most popular terms. I end up with facets like "a", "the", "from", "includes".

So I am thinking what would be ideal for my case is to be able to filter the facet terms using a wildcard, as opposed to the docs. So far I have not discovered a way to do this. Is this possible with elasticsearch out of the box? Is there another, better solution for my problem?

## Thanks for your help! Mark

--

---

<div class="post-metadata">

**Author:** ![Mark\_Waddle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_waddle/32/2608_2.png) [@Mark\_Waddle](https://discuss.elastic.co/u/Mark_Waddle)\
**Post date:** [August 23, 2012, 2:27pm UTC](https://discuss.elastic.co/t/filter-the-facet-terms/8825/3 "2012-08-23T14:27:21Z")

</div>

Thanks David. Unfortunately I've already tried that. The first ten terms in  
my abstract field end up being "the", "a", etc.

What I need are the top 10 terms in field Y that start with X. Hence why I  
was thinking that a filter on the terms would be good.

Any other ideas?

On Thursday, August 23, 2012, David Pilato wrote:

> Wildcard is not available as a filter.  
> Wildcard is slow.
> 
> I would define my own analyzer for that field with edgengram tokenizer (  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/edgengram-tokenizer.html))  
> and an english analyzer.  
> Then, a Term facet on that field could give you the first 10 terms.
> 
> My 2 cents.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 23 août 2012 à 08:32, Mark Waddle \<[mark@markwaddle.com](mailto:mark@markwaddle.com)\<javascript:\_e({}, 'cvml', 'mark@markwaddle.com');\>\>  
> a écrit :
> 
> I have a field called abstract that has numerous words per document, as  
> you can imagine. I would like to use this field as a dictionary of sorts  
> for autocompletion of individual search terms. I have done some research on  
> the autocomplete solutions out there and it seems that they all work for  
> fields that have single or few terms per document, but not for my case  
> where the number of terms per document can be in the hundreds.
> 
> I tried to do a wildcard on an edgengram field in combination with  
> highlighting, but that just gives the top X docs that match that. So I will  
> get 1,000s of docs that match "wireless", then 1,000s of docs that match  
> "wired", etc. Not gonna work.
> 
> I also tried faceting on a tokenized field, but of course I get all of the  
> popular terms in the facet as opposed to the terms that match my query. I  
> tried the facet filter, but that only filters the docs that the facet  
> matches against, still returning all of the most popular terms. I end up  
> with facets like "a", "the", "from", "includes".
> 
> So I am thinking what would be ideal for my case is to be able to filter  
> the facet _terms_ using a wildcard, as opposed to the docs. So far I have  
> not discovered a way to do this. Is this possible with elasticsearch out of  
> the box? Is there another, better solution for my problem?
> 
> Thanks for your help!  
> Mark
> 
> --
> 
> --

--

- Mark

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 23, 2012, 2:31pm UTC](https://discuss.elastic.co/t/filter-the-facet-terms/8825/4 "2012-08-23T14:31:10Z")

</div>

Hi Mark

> So I am thinking what would be ideal for my case is to be able to  
> filter the facet terms using a wildcard, as opposed to the docs. So  
> far I have not discovered a way to do this. Is this possible with  
> elasticsearch out of the box? Is there another, better solution for my  
> problem?

A gist showing actual data demonstrating what you are currently doing  
and what you would like to achieve would make this easier to follow.

But based on your last paragraph, you should be able to do that using  
regex patterns in your terms facet.

See Regex Patterns on:

> **[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.

clint

--

---

<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, 3:15am UTC](https://discuss.elastic.co/t/filter-the-facet-terms/8825/5 "2017-07-06T03:15:19Z")

</div>


