# Creating a bucket with whole field not just terms

**URL:** <https://discuss.elastic.co/t/creating-a-bucket-with-whole-field-not-just-terms/35472>\
**Category:** Elasticsearch\
**Created:** [November 24, 2015, 4:38pm UTC](https://discuss.elastic.co/t/creating-a-bucket-with-whole-field-not-just-terms/35472 "2015-11-24T16:38:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_Diego\_Calle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juan_diego_calle/32/6037_2.png) [@Juan\_Diego\_Calle](https://discuss.elastic.co/u/Juan_Diego_Calle)\
**Post date:** [November 24, 2015, 4:38pm UTC](https://discuss.elastic.co/t/creating-a-bucket-with-whole-field-not-just-terms/35472/1 "2015-11-24T16:38:10Z")

</div>

I am doing some aggregations and I am using a field named "city" to get buckets or groups, the problem was that for cities with 2 or more words i was getting a bucket per word. For example Los Angeles and Mexico City, I got 4 buckets. So as I did some research and I found this

> **[Get Accurate Results with Elasticsearch Aggregations: Configure a Custom...](http://qbox.io/blog/elasticsearch-aggregation-custom-analyzer)**
>
> It can be challenging to get the right outcomes from your Elasticsearch aggregations. But it's possible to get precise results with tokenization, exact mappings, and a custom analyzer.
> 
> In this article, we explain some of the subtleties that are...

  
I added that custom analyzer and it worked,  
But the problem is that if I search now for Mexico i wont get any results, I have to have "mexico city". I can think of solution and it is 2 duplicate the field and have different analyzers I dont know if this is the correct approach or if there is another way.

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [November 24, 2015, 4:53pm UTC](https://discuss.elastic.co/t/creating-a-bucket-with-whole-field-not-just-terms/35472/2 "2015-11-24T16:53:58Z")

</div>

Take a look at the `fields` parameter in the mapping: [https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html)

This will allow you to index one field in your json document in multiple ways so you can have it use the standard analyzer for searching and you custom aggregation analyzer for aggregations

Hope that helps

---

<div class="post-metadata">

**Author:** ![Juan\_Diego\_Calle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juan_diego_calle/32/6037_2.png) [@Juan\_Diego\_Calle](https://discuss.elastic.co/u/Juan_Diego_Calle)\
**Post date:** [November 24, 2015, 4:59pm UTC](https://discuss.elastic.co/t/creating-a-bucket-with-whole-field-not-just-terms/35472/3 "2015-11-24T16:59:43Z")

</div>

Thanks, exactly what I was looking for

---

<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 5, 2017, 11:36pm UTC](https://discuss.elastic.co/t/creating-a-bucket-with-whole-field-not-just-terms/35472/4 "2017-07-05T23:36:14Z")

</div>


