# Specifying analyzer for search facet

**URL:** https://discuss.elastic.co/t/specifying-analyzer-for-search-facet/7591
**Category:** Elasticsearch
**Created:** [May 8, 2012, 1:28am UTC](https://discuss.elastic.co/t/specifying-analyzer-for-search-facet/7591 "2012-05-08T01:28:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jonathan\_Ness](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@Jonathan\_Ness](https://discuss.elastic.co/u/Jonathan_Ness)
#### Post date: [May 8, 2012, 1:28am UTC](https://discuss.elastic.co/t/specifying-analyzer-for-search-facet/7591/1 "2012-05-08T01:28:21Z")

</div>

## I'd like to use the whitespace analyzer to apply for facet operations. It seems to be using the default analyzer, not the analyzer I specify.

I create a new index with a number of fields:

create :mappings =\> {  
:xplico =\> {  
:properties =\> {  
...  
:contenttype =\> { :type =\> 'string', :analyzer =\>  
'whitespace' },  
...

I then store a number of records, populating this :contenttype  
property with values such as:

application/x-gzip; charset=binary  
image/png; charset=binary  
image/gif; charset=binary  
...

Now I want a listing of the number of records having contenttype image/  
png, image/gif, application/x-gzip, etc.

s = Tire.search 'xplico' do  
query { all }  
facet 'contenttype', :global =\> true do  
terms :contenttype  
end  
end

s.results.facets['contenttype']['terms'].each do |f|  
puts "#{f['term'].ljust(20)} #{f['count']}"  
end

I would expect

application/x-gzip 45  
image/png; 29  
image/gif; 12

Instead I get

charset 162  
binary 159  
image 114  
jpeg 70  
x 45  
gzip 45  
application 45  
png 29  
gif 12  
text 3

Why didn't it use teh whitespace analyzer?

Thanks.

Jonathan

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 9, 2012, 9:22am UTC](https://discuss.elastic.co/t/specifying-analyzer-for-search-facet/7591/2 "2012-05-09T09:22:37Z")

</div>

Your mapping probably did not apply. You can easily check what the mapping  
is for a specific type using the get mapping API, and if its not what you  
set, then either your Tire config is wrong, or maybe you tried to change  
the mapping on an index that already exists and already has mappings for  
that field?

On Tue, May 8, 2012 at 4:28 AM, Jonathan Ness [jness123456789@gmail.com](mailto:jness123456789@gmail.com)wrote:

> ## I'd like to use the whitespace analyzer to apply for facet operations. It seems to be using the default analyzer, not the analyzer I specify.
> 
> I create a new index with a number of fields:
> 
> create :mappings =\> {  
> :xplico =\> {  
> :properties =\> {  
> ...  
> :contenttype =\> { :type =\> 'string', :analyzer =\>  
> 'whitespace' },  
> ...
> 
> I then store a number of records, populating this :contenttype  
> property with values such as:
> 
> application/x-gzip; charset=binary  
> image/png; charset=binary  
> image/gif; charset=binary  
> ...
> 
> Now I want a listing of the number of records having contenttype image/  
> png, image/gif, application/x-gzip, etc.
> 
> s = Tire.search 'xplico' do  
> query { all }  
> facet 'contenttype', :global =\> true do  
> terms :contenttype  
> end  
> end
> 
> s.results.facets['contenttype']['terms'].each do |f|  
> puts "#{f['term'].ljust(20)} #{f['count']}"  
> end
> 
> I would expect
> 
> application/x-gzip 45  
> image/png; 29  
> image/gif; 12
> 
> Instead I get
> 
> charset 162  
> binary 159  
> image 114  
> jpeg 70  
> x 45  
> gzip 45  
> application 45  
> png 29  
> gif 12  
> text 3
> 
> Why didn't it use teh whitespace analyzer?
> 
> Thanks.
> 
> Jonathan

---

<div class="post-metadata">

### Author: ![Jonathan\_Ness](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@Jonathan\_Ness](https://discuss.elastic.co/u/Jonathan_Ness)
#### Post date: [May 11, 2012, 1:48am UTC](https://discuss.elastic.co/t/specifying-analyzer-for-search-facet/7591/3 "2012-05-11T01:48:30Z")

</div>

Hi Shay,

## To test your suggestion, I created a simpler example and I really do think that the analyzer is not working in conjunction with facets correctly. Here is the complete example to demonstrate it:

require 'rubygems'  
require 'tire'

Tire.index 'demo' do  
delete

create :mappings =\> {  
:demo =\> {  
:properties =\> {  
:demostring =\> { :type =\> 'string', :analyzer =\>  
'whitespace' }  
}  
}  
}

store :demostring =\> 'One/Two'  
store :demostring =\> 'One Two'

refresh  
end

s = Tire.search 'demo' do  
query { all }  
facet 'demostring', :global =\> true do  
terms :demostring  
end  
end

## puts "Found #{s.results.count} entries: #{s.results.map(&:demostring).join(', ')}" puts "Counts by demostring:", "-"\*25 s.results.facets['demostring']['terms'].each do |f| puts "#{f['term'].ljust(20)} #{f['count']}" end

With a whitespace analyzer, I would expect one instance of the string  
'One', one instance of the string 'Two', and one instance of the  
string 'One/Two'. Instead, I got the following:

## Counts by demostring:

two 2  
one 2

Any suggestions for what I might be doing wrong here?

Thanks!!

Jonathan

On May 9, 2:22 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Your mapping probably did not apply. You can easily check what the mapping  
> is for a specific type using the get mapping API, and if its not what you  
> set, then either your Tire config is wrong, or maybe you tried to change  
> the mapping on an index that already exists and already has mappings for  
> that field?
> 
> On Tue, May 8, 2012 at 4:28 AM, Jonathan Ness [jness123456...@gmail.com](mailto:jness123456...@gmail.com)wrote:
> 
> > ## I'd like to use the whitespace analyzer to apply for facet operations. It seems to be using the default analyzer, not the analyzer I specify.
> > 
> > I create a new index with a number of fields:
> 
> > create :mappings =\> {  
> > :xplico =\> {  
> > :properties =\> {  
> > ...  
> > :contenttype =\> { :type =\> 'string', :analyzer =\>  
> > 'whitespace' },  
> > ...
> 
> > I then store a number of records, populating this :contenttype  
> > property with values such as:
> 
> > application/x-gzip; charset=binary  
> > image/png; charset=binary  
> > image/gif; charset=binary  
> > ...
> 
> > Now I want a listing of the number of records having contenttype image/  
> > png, image/gif, application/x-gzip, etc.
> 
> > s = Tire.search 'xplico' do  
> > query { all }  
> > facet 'contenttype', :global =\> true do  
> > terms :contenttype  
> > end  
> > end
> 
> > s.results.facets['contenttype']['terms'].each do |f|  
> > puts "#{f['term'].ljust(20)} #{f['count']}"  
> > end
> 
> > I would expect
> 
> > application/x-gzip 45  
> > image/png; 29  
> > image/gif; 12
> 
> > Instead I get
> 
> > charset 162  
> > binary 159  
> > image 114  
> > jpeg 70  
> > x 45  
> > gzip 45  
> > application 45  
> > png 29  
> > gif 12  
> > text 3
> 
> > Why didn't it use teh whitespace analyzer?
> 
> > Thanks.
> 
> > Jonathan

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 13, 2012, 12:04pm UTC](https://discuss.elastic.co/t/specifying-analyzer-for-search-facet/7591/4 "2012-05-13T12:04:53Z")

</div>

curl recreation are best (and I think you can turn on a flag to log curl  
operations with Tire), here is one that works:  
[gist:2688072 · GitHub](https://gist.github.com/2688072).

On Fri, May 11, 2012 at 4:48 AM, Jonathan Ness [jness123456789@gmail.com](mailto:jness123456789@gmail.com)wrote:

> Hi Shay,
> 
> ## To test your suggestion, I created a simpler example and I really do think that the analyzer is not working in conjunction with facets correctly. Here is the complete example to demonstrate it:
> 
> require 'rubygems'  
> require 'tire'
> 
> Tire.index 'demo' do  
> delete
> 
> create :mappings =\> {  
> :demo =\> {  
> :properties =\> {  
> :demostring =\> { :type =\> 'string', :analyzer =\>  
> 'whitespace' }  
> }  
> }  
> }
> 
> store :demostring =\> 'One/Two'  
> store :demostring =\> 'One Two'
> 
> refresh  
> end
> 
> s = Tire.search 'demo' do  
> query { all }  
> facet 'demostring', :global =\> true do  
> terms :demostring  
> end  
> end
> 
> ## puts "Found #{s.results.count} entries: #{s.results.map(&:demostring).join(', ')}" puts "Counts by demostring:", "-"\*25 s.results.facets['demostring']['terms'].each do |f| puts "#{f['term'].ljust(20)} #{f['count']}" end
> 
> With a whitespace analyzer, I would expect one instance of the string  
> 'One', one instance of the string 'Two', and one instance of the  
> string 'One/Two'. Instead, I got the following:
> 
> ## Counts by demostring:
> 
> two 2  
> one 2
> 
> Any suggestions for what I might be doing wrong here?
> 
> Thanks!!
> 
> Jonathan
> 
> On May 9, 2:22 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Your mapping probably did not apply. You can easily check what the  
> > mapping  
> > is for a specific type using the get mapping API, and if its not what  
> > you  
> > set, then either your Tire config is wrong, or maybe you tried to change  
> > the mapping on an index that already exists and already has mappings for  
> > that field?
> > 
> > On Tue, May 8, 2012 at 4:28 AM, Jonathan Ness \<[jness123456...@gmail.com](mailto:jness123456...@gmail.com)  
> > wrote:
> > 
> > > ## I'd like to use the whitespace analyzer to apply for facet operations. It seems to be using the default analyzer, not the analyzer I specify.
> > > 
> > > I create a new index with a number of fields:
> > 
> > > create :mappings =\> {  
> > > :xplico =\> {  
> > > :properties =\> {  
> > > ...  
> > > :contenttype =\> { :type =\> 'string', :analyzer =\>  
> > > 'whitespace' },  
> > > ...
> > 
> > > I then store a number of records, populating this :contenttype  
> > > property with values such as:
> > 
> > > application/x-gzip; charset=binary  
> > > image/png; charset=binary  
> > > image/gif; charset=binary  
> > > ...
> > 
> > > Now I want a listing of the number of records having contenttype image/  
> > > png, image/gif, application/x-gzip, etc.
> > 
> > > s = Tire.search 'xplico' do  
> > > query { all }  
> > > facet 'contenttype', :global =\> true do  
> > > terms :contenttype  
> > > end  
> > > end
> > 
> > > s.results.facets['contenttype']['terms'].each do |f|  
> > > puts "#{f['term'].ljust(20)} #{f['count']}"  
> > > end
> > 
> > > I would expect
> > 
> > > application/x-gzip 45  
> > > image/png; 29  
> > > image/gif; 12
> > 
> > > Instead I get
> > 
> > > charset 162  
> > > binary 159  
> > > image 114  
> > > jpeg 70  
> > > x 45  
> > > gzip 45  
> > > application 45  
> > > png 29  
> > > gif 12  
> > > text 3
> > 
> > > Why didn't it use teh whitespace analyzer?
> > 
> > > Thanks.
> > 
> > > Jonathan

---

<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:29am UTC](https://discuss.elastic.co/t/specifying-analyzer-for-search-facet/7591/5 "2017-07-06T03:29:04Z")

</div>


