# Facetting by first letter

**URL:** https://discuss.elastic.co/t/facetting-by-first-letter/17152
**Category:** Elasticsearch
**Created:** [April 23, 2014, 3:51pm UTC](https://discuss.elastic.co/t/facetting-by-first-letter/17152 "2014-04-23T15:51:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Stefan\_Kruse](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stefan\_Kruse](https://discuss.elastic.co/u/Stefan_Kruse)
#### Post date: [April 23, 2014, 3:51pm UTC](https://discuss.elastic.co/t/facetting-by-first-letter/17152/1 "2014-04-23T15:51:06Z")

</div>

Hi, i would like to facett by the first letter of search results. By Solar  
i need to make a field with the first letter inside. Is there by  
elasticseach maybe a cool function for this? I would to make a alphabetical  
list like : A B C D but only for letters where a results behind. Regards  
and thanks Stefan

--  
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/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)
#### Post date: [April 23, 2014, 4:01pm UTC](https://discuss.elastic.co/t/facetting-by-first-letter/17152/2 "2014-04-23T16:01:02Z")

</div>

You can for sure define 26 facets, each using a term script:

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

But I'm pretty sure this can be done using script fields, haven't tried  
that one before tho

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

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Wed, Apr 23, 2014 at 6:51 PM, Stefan Kruse  
[info@all-around-shipping.de](mailto:info@all-around-shipping.de)wrote:

> Hi, i would like to facett by the first letter of search results. By Solar  
> i need to make a field with the first letter inside. Is there by  
> elasticseach maybe a cool function for this? I would to make a alphabetical  
> list like : A B C D but only for letters where a results behind. Regards  
> and thanks Stefan
> 
> --  
> 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/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.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/CAHTr4ZvpMr2m1v--W8%3DE680UCuw8JQ%3D0zn8AvbqtOSn0LeW\_9w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZvpMr2m1v--W8%3DE680UCuw8JQ%3D0zn8AvbqtOSn0LeW_9w%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: [April 23, 2014, 4:53pm UTC](https://discuss.elastic.co/t/facetting-by-first-letter/17152/3 "2014-04-23T16:53:15Z")

</div>

You can easily accomplish this with value scripts, but I would still choose  
the Solr approach of indexing a new field for performance reasons. If any  
content is static in nature, I would always opt to handle the processing at  
index time. Not only will you save CPU cycles by not having to run a  
script, but you can also control exactly how the new field's data is  
cached/used.

--  
Ivan

On Wed, Apr 23, 2014 at 9:01 AM, Itamar Syn-Hershko [itamar@code972.com](mailto:itamar@code972.com)wrote:

> You can for sure define 26 facets, each using a term script:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html#_term_scripts)
> 
> But I'm pretty sure this can be done using script fields, haven't tried  
> that one before tho  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html#_script_field)
> 
> --
> 
> Itamar Syn-Hershko  
> [http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
> Freelance Developer & Consultant  
> Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)
> 
> On Wed, Apr 23, 2014 at 6:51 PM, Stefan Kruse \<[info@all-around-shipping.de](mailto:info@all-around-shipping.de)
> 
> > wrote:
> 
> > Hi, i would like to facett by the first letter of search results. By  
> > Solar i need to make a field with the first letter inside. Is there by  
> > elasticseach maybe a cool function for this? I would to make a alphabetical  
> > list like : A B C D but only for letters where a results behind. Regards  
> > and thanks Stefan
> > 
> > --  
> > 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/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ff058c04-b7ba-48c6-b3d6-9ca1a14d6191%40googlegroups.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/CAHTr4ZvpMr2m1v--W8%3DE680UCuw8JQ%3D0zn8AvbqtOSn0LeW\_9w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZvpMr2m1v--W8%3DE680UCuw8JQ%3D0zn8AvbqtOSn0LeW_9w%40mail.gmail.com)[https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZvpMr2m1v--W8%3DE680UCuw8JQ%3D0zn8AvbqtOSn0LeW\_9w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZvpMr2m1v--W8%3DE680UCuw8JQ%3D0zn8AvbqtOSn0LeW_9w%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%3DcQCZuO0Wma2ijGuxrOo7jUDSaqeN1XyzgJTofzngFR1Kow%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCZuO0Wma2ijGuxrOo7jUDSaqeN1XyzgJTofzngFR1Kow%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:34am UTC](https://discuss.elastic.co/t/facetting-by-first-letter/17152/4 "2017-07-06T01:34:01Z")

</div>


