# Retaining case in a faceted search

**URL:** https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689
**Category:** Elasticsearch
**Created:** [February 13, 2012, 5:14pm UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689 "2012-02-13T17:14:01Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![csh\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/csh_2/32/2996_2.png) [@csh\_2](https://discuss.elastic.co/u/csh_2)
#### Post date: [February 13, 2012, 5:14pm UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689/1 "2012-02-13T17:14:01Z")

</div>

Is there a way to do faceted searches using the Search API AND  
maintain case. For example...

curl -X POST "[http://localhost:9200/automobiles/automobile/\_search](http://localhost:9200/automobiles/automobile/_search)?  
pretty=true&q=make:B\*" -d '{"size" : "0", "facets" : {"make" :  
{ "terms" : {"field" : "make"} }}}'

...returns...

{  
...  
"facets" : {  
"make" : {  
...  
"terms" : [ {  
"term" : "bmw",  
"count" : 1654  
}, {  
"term" : "buick",  
"count" : 362  
}, {  
...  
} ]  
}  
}

...but I want to retain the case ("BMW", "Buick").

Thanks in advance, Chuck

---

<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: [February 13, 2012, 5:33pm UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689/2 "2012-02-13T17:33:37Z")

</div>

Hi Chuck,

When faceting on strings, they should either be not analyzed  
(preferred) or tokenized with a KeywordTokenizer. What is happening in  
your case is the terms are being indexed as lowercase by the default  
analyzer.

--  
Ivan

On Mon, Feb 13, 2012 at 9:14 AM, csh [chuck.han@gmail.com](mailto:chuck.han@gmail.com) wrote:

> Is there a way to do faceted searches using the Search API AND  
> maintain case. For example...
> 
> curl -X POST "[http://localhost:9200/automobiles/automobile/\_search](http://localhost:9200/automobiles/automobile/_search)?  
> pretty=true&q=make:B\*" -d '{"size" : "0", "facets" : {"make" :  
> { "terms" : {"field" : "make"} }}}'
> 
> ...returns...
> 
> {  
> ...  
> "facets" : {  
> "make" : {  
> ...  
> "terms" : [ {  
> "term" : "bmw",  
> "count" : 1654  
> }, {  
> "term" : "buick",  
> "count" : 362  
> }, {  
> ...  
> } ]  
> }  
> }
> 
> ...but I want to retain the case ("BMW", "Buick").
> 
> Thanks in advance, Chuck

---

<div class="post-metadata">

### Author: ![csh\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/csh_2/32/2996_2.png) [@csh\_2](https://discuss.elastic.co/u/csh_2)
#### Post date: [February 13, 2012, 7:02pm UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689/3 "2012-02-13T19:02:02Z")

</div>

Thanks for the quick response, Ivan! Will look into how to do this  
(don't tell me :-)), as I am an ES newbie...

On Feb 13, 9:33 am, Ivan Brusic [i...@brusic.com](mailto:i...@brusic.com) wrote:

> Hi Chuck,
> 
> When faceting on strings, they should either be not analyzed  
> (preferred) or tokenized with a KeywordTokenizer. What is happening in  
> your case is the terms are being indexed as lowercase by the default  
> analyzer.
> 
> --  
> Ivan
> 
> On Mon, Feb 13, 2012 at 9:14 AM, csh [chuck....@gmail.com](mailto:chuck....@gmail.com) wrote:
> 
> > Is there a way to do faceted searches using the Search API AND  
> > maintain case. For example...
> 
> > curl -X POST "[http://localhost:9200/automobiles/automobile/\_search](http://localhost:9200/automobiles/automobile/_search)?  
> > pretty=true&q=make:B\*" -d '{"size" : "0", "facets" : {"make" :  
> > { "terms" : {"field" : "make"} }}}'
> 
> > ...returns...
> 
> > {  
> > ...  
> > "facets" : {  
> > "make" : {  
> > ...  
> > "terms" : [ {  
> > "term" : "bmw",  
> > "count" : 1654  
> > }, {  
> > "term" : "buick",  
> > "count" : 362  
> > }, {  
> > ...  
> > } ]  
> > }  
> > }
> 
> > ...but I want to retain the case ("BMW", "Buick").
> 
> > Thanks in advance, Chuck

---

<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: [February 14, 2012, 2:09pm UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689/4 "2012-02-14T14:09:35Z")

</div>

Just in case you did not find out how, you need to explicitly define the mapping for that field to set index to not\_analyzed. SEt the mapping in the create index API (simplest) when you create the index.

On Monday, February 13, 2012 at 9:02 PM, csh wrote:

> Thanks for the quick response, Ivan! Will look into how to do this  
> (don't tell me :-)), as I am an ES newbie...
> 
> On Feb 13, 9:33 am, Ivan Brusic \<[i...@brusic.com](mailto:i...@brusic.com) ([http://brusic.com](http://brusic.com))\> wrote:
> 
> > Hi Chuck,
> > 
> > When faceting on strings, they should either be not analyzed  
> > (preferred) or tokenized with a KeywordTokenizer. What is happening in  
> > your case is the terms are being indexed as lowercase by the default  
> > analyzer.
> > 
> > --  
> > Ivan
> > 
> > On Mon, Feb 13, 2012 at 9:14 AM, csh \<[chuck....@gmail.com](mailto:chuck....@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > Is there a way to do faceted searches using the Search API AND  
> > > maintain case. For example...
> > 
> > > curl -X POST "[http://localhost:9200/automobiles/automobile/\_search](http://localhost:9200/automobiles/automobile/_search)?  
> > > pretty=true&q=make:B\*" -d '{"size" : "0", "facets" : {"make" :  
> > > { "terms" : {"field" : "make"} }}}'
> > 
> > > ...returns...
> > 
> > > {  
> > > ...  
> > > "facets" : {  
> > > "make" : {  
> > > ...  
> > > "terms" : [ {  
> > > "term" : "bmw",  
> > > "count" : 1654  
> > > }, {  
> > > "term" : "buick",  
> > > "count" : 362  
> > > }, {  
> > > ...  
> > > } ]  
> > > }  
> > > }
> > 
> > > ...but I want to retain the case ("BMW", "Buick").
> > 
> > > Thanks in advance, Chuck

---

<div class="post-metadata">

### Author: ![csh\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/csh_2/32/2996_2.png) [@csh\_2](https://discuss.elastic.co/u/csh_2)
#### Post date: [February 14, 2012, 4:58pm UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689/5 "2012-02-14T16:58:02Z")

</div>

I'm not quite getting the results I expect: I think I'm indexing the  
way you suggested...

curl -XPUT localhost:9200/cars?pretty=true -d '{"index" :  
{"analysis" : {"analyzer" : {"default" : {"type" : "keyword"}}}}}'

...because after populating ES, the following query gives me the fully-  
retained fields:

curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
pretty=true&q=make:\*" -d '{"size" : "0", "facets" : {"make" :  
{ "terms" : {"field" : "make"} }}}'

I can even do a query now in which I ask for all "makes" that end in  
"n"...

curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
pretty=true&q=make:\*n" -d '{"size" : "0", "facets" : {"make" :  
{ "terms" : {"field" : "make"} }}}'

...and I get the right result:

{  
...  
"facets" : {  
"make" : {  
"\_type" : "terms",  
"missing" : 0,  
"total" : 3,  
"other" : 0,  
"terms" : [ {  
"term" : "Aston Martin",  
"count" : 2  
}, {  
"term" : "Nissan",  
"count" : 1  
} ]  
}  
}  
}

However, if I ask for all "makes" that start with "a" or  
"A" (q=make:A\* or q=make:a\*), I get no results (there should be  
several--at least one as shown in the above example):

curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
pretty=true&q=make:a\*" -d '{"size" : "0", "facets" : {"make" :  
{ "terms" : {"field" : "make"} }}}'

Is that a bug, or is there something I'm missing?

thanks in advance, Chuck

On Feb 13, 9:33 am, Ivan Brusic [i...@brusic.com](mailto:i...@brusic.com) wrote:

> Hi Chuck,
> 
> When faceting on strings, they should either be not analyzed  
> (preferred) or tokenized with a KeywordTokenizer. What is happening in  
> yourcaseis the terms are being indexed as lowercase by the default  
> analyzer.
> 
> --  
> Ivan
> 
> On Mon, Feb 13, 2012 at 9:14 AM, csh [chuck....@gmail.com](mailto:chuck....@gmail.com) wrote:
> 
> > Is there a way to dofacetedsearches using the Search API AND  
> > maintaincase. For example...
> 
> > curl -X POST "[http://localhost:9200/automobiles/automobile/\_search](http://localhost:9200/automobiles/automobile/_search)?  
> > pretty=true&q=make:B\*" -d '{"size" : "0", "facets" : {"make" :  
> > { "terms" : {"field" : "make"} }}}'
> 
> > ...returns...
> 
> > {  
> > ...  
> > "facets" : {  
> > "make" : {  
> > ...  
> > "terms" : [ {  
> > "term" : "bmw",  
> > "count" : 1654  
> > }, {  
> > "term" : "buick",  
> > "count" : 362  
> > }, {  
> > ...  
> > } ]  
> > }  
> > }
> 
> > ...but I want to retain thecase("BMW", "Buick").
> 
> > Thanks in advance, Chuck

---

<div class="post-metadata">

### Author: ![csh\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/csh_2/32/2996_2.png) [@csh\_2](https://discuss.elastic.co/u/csh_2)
#### Post date: [February 14, 2012, 8:34pm UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689/6 "2012-02-14T20:34:15Z")

</div>

Got it! Need to put the wildcard directive in explicitly:

curl -X POST "[http://localhost:9200/cars/car/\_search?pretty=true](http://localhost:9200/cars/car/_search?pretty=true)" -d  
'{"size" : "0", "query": {"wildcard" : { "make" : "A\*" }}, "facets" :  
{"make" : { "terms" : {"field" : "make"} }}}'

And, as expected, the wildcard is case-sensitive...

thanks, Chuck

On Feb 14, 8:58 am, csh [chuck....@gmail.com](mailto:chuck....@gmail.com) wrote:

> I'm not quite getting the results I expect: I think I'm indexing the  
> way you suggested...
> 
> curl -XPUT localhost:9200/cars?pretty=true -d '{"index" :  
> {"analysis" : {"analyzer" : {"default" : {"type" : "keyword"}}}}}'
> 
> ...because after populating ES, the following query gives me the fully-  
> retained fields:
> 
> curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
> pretty=true&q=make:\*" -d '{"size" : "0", "facets" : {"make" :  
> { "terms" : {"field" : "make"} }}}'
> 
> I can even do a query now in which I ask for all "makes" that end in  
> "n"...
> 
> curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
> pretty=true&q=make:\*n" -d '{"size" : "0", "facets" : {"make" :  
> { "terms" : {"field" : "make"} }}}'
> 
> ...and I get the right result:
> 
> {  
> ...  
> "facets" : {  
> "make" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "total" : 3,  
> "other" : 0,  
> "terms" : [ {  
> "term" : "Aston Martin",  
> "count" : 2  
> }, {  
> "term" : "Nissan",  
> "count" : 1  
> } ]  
> }  
> }
> 
> }
> 
> However, if I ask for all "makes" that start with "a" or  
> "A" (q=make:A\* or q=make:a\*), I get no results (there should be  
> several--at least one as shown in the above example):
> 
> curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
> pretty=true&q=make:a\*" -d '{"size" : "0", "facets" : {"make" :  
> { "terms" : {"field" : "make"} }}}'
> 
> Is that a bug, or is there something I'm missing?
> 
> thanks in advance, Chuck
> 
> On Feb 13, 9:33 am, Ivan Brusic [i...@brusic.com](mailto:i...@brusic.com) wrote:
> 
> > Hi Chuck,
> 
> > When faceting on strings, they should either be not analyzed  
> > (preferred) or tokenized with a KeywordTokenizer. What is happening in  
> > yourcaseis the terms are being indexed as lowercase by the default  
> > analyzer.
> 
> > --  
> > Ivan
> 
> > On Mon, Feb 13, 2012 at 9:14 AM, csh [chuck....@gmail.com](mailto:chuck....@gmail.com) wrote:
> > 
> > > Is there a way to dofacetedsearches using the Search API AND  
> > > maintaincase. For example...
> 
> > > curl -X POST "[http://localhost:9200/automobiles/automobile/\_search](http://localhost:9200/automobiles/automobile/_search)?  
> > > pretty=true&q=make:B\*" -d '{"size" : "0", "facets" : {"make" :  
> > > { "terms" : {"field" : "make"} }}}'
> 
> > > ...returns...
> 
> > > {  
> > > ...  
> > > "facets" : {  
> > > "make" : {  
> > > ...  
> > > "terms" : [ {  
> > > "term" : "bmw",  
> > > "count" : 1654  
> > > }, {  
> > > "term" : "buick",  
> > > "count" : 362  
> > > }, {  
> > > ...  
> > > } ]  
> > > }  
> > > }
> 
> > > ...but I want to retain thecase("BMW", "Buick").
> 
> > > Thanks in advance, Chuck

---

<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: [February 15, 2012, 10:32am UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689/7 "2012-02-15T10:32:41Z")

</div>

Note, what you are doing is storing all text fields using the keyword analyzer, I am not sure that its what you really want. Only use that on fields that you want to facet, possibly with multi field mapping.

On Tuesday, February 14, 2012 at 10:34 PM, csh wrote:

> Got it! Need to put the wildcard directive in explicitly:
> 
> curl -X POST "[http://localhost:9200/cars/car/\_search?pretty=true](http://localhost:9200/cars/car/_search?pretty=true)" -d  
> '{"size" : "0", "query": {"wildcard" : { "make" : "A\*" }}, "facets" :  
> {"make" : { "terms" : {"field" : "make"} }}}'
> 
> And, as expected, the wildcard is case-sensitive...
> 
> thanks, Chuck
> 
> On Feb 14, 8:58 am, csh \<[chuck....@gmail.com](mailto:chuck....@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > I'm not quite getting the results I expect: I think I'm indexing the  
> > way you suggested...
> > 
> > curl -XPUT localhost:9200/cars?pretty=true -d '{"index" :  
> > {"analysis" : {"analyzer" : {"default" : {"type" : "keyword"}}}}}'
> > 
> > ...because after populating ES, the following query gives me the fully-  
> > retained fields:
> > 
> > curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
> > pretty=true&q=make:\*" -d '{"size" : "0", "facets" : {"make" :  
> > { "terms" : {"field" : "make"} }}}'
> > 
> > I can even do a query now in which I ask for all "makes" that end in  
> > "n"...
> > 
> > curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
> > pretty=true&q=make:\*n" -d '{"size" : "0", "facets" : {"make" :  
> > { "terms" : {"field" : "make"} }}}'
> > 
> > ...and I get the right result:
> > 
> > {  
> > ...  
> > "facets" : {  
> > "make" : {  
> > "\_type" : "terms",  
> > "missing" : 0,  
> > "total" : 3,  
> > "other" : 0,  
> > "terms" : [ {  
> > "term" : "Aston Martin",  
> > "count" : 2  
> > }, {  
> > "term" : "Nissan",  
> > "count" : 1  
> > } ]  
> > }  
> > }
> > 
> > }
> > 
> > However, if I ask for all "makes" that start with "a" or  
> > "A" (q=make:A\* or q=make:a\*), I get no results (there should be  
> > several--at least one as shown in the above example):
> > 
> > curl -X POST "[http://localhost:9200/cars/car/\_search](http://localhost:9200/cars/car/_search)?  
> > pretty=true&q=make:a\*" -d '{"size" : "0", "facets" : {"make" :  
> > { "terms" : {"field" : "make"} }}}'
> > 
> > Is that a bug, or is there something I'm missing?
> > 
> > thanks in advance, Chuck
> > 
> > On Feb 13, 9:33 am, Ivan Brusic \<[i...@brusic.com](mailto:i...@brusic.com) ([http://brusic.com](http://brusic.com))\> wrote:
> > 
> > > Hi Chuck,
> > 
> > > When faceting on strings, they should either be not analyzed  
> > > (preferred) or tokenized with a KeywordTokenizer. What is happening in  
> > > yourcaseis the terms are being indexed as lowercase by the default  
> > > analyzer.
> > 
> > > --  
> > > Ivan
> > 
> > > On Mon, Feb 13, 2012 at 9:14 AM, csh \<[chuck....@gmail.com](mailto:chuck....@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > > 
> > > > Is there a way to dofacetedsearches using the Search API AND  
> > > > maintaincase. For example...
> > 
> > > > curl -X POST "[http://localhost:9200/automobiles/automobile/\_search](http://localhost:9200/automobiles/automobile/_search)?  
> > > > pretty=true&q=make:B\*" -d '{"size" : "0", "facets" : {"make" :  
> > > > { "terms" : {"field" : "make"} }}}'
> > 
> > > > ...returns...
> > 
> > > > {  
> > > > ...  
> > > > "facets" : {  
> > > > "make" : {  
> > > > ...  
> > > > "terms" : [ {  
> > > > "term" : "bmw",  
> > > > "count" : 1654  
> > > > }, {  
> > > > "term" : "buick",  
> > > > "count" : 362  
> > > > }, {  
> > > > ...  
> > > > } ]  
> > > > }  
> > > > }
> > 
> > > > ...but I want to retain thecase("BMW", "Buick").
> > 
> > > > Thanks in advance, Chuck

---

<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:39am UTC](https://discuss.elastic.co/t/retaining-case-in-a-faceted-search/6689/8 "2017-07-06T03:39:16Z")

</div>


