# Elasticsearch Java api split a field

**URL:** https://discuss.elastic.co/t/elasticsearch-java-api-split-a-field/48555
**Category:** Elasticsearch
**Created:** [April 27, 2016, 1:02pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-split-a-field/48555 "2016-04-27T13:02:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![maher](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@maher](https://discuss.elastic.co/u/maher)
#### Post date: [April 27, 2016, 1:02pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-split-a-field/48555/1 "2016-04-27T13:02:53Z")

</div>

Hi, I am trying to execute an aggregation to get the distinct"roles"  
the field "roles" wich contain different roles separated with comma here an example:

```
          "roles": ["\"ROLE_CUSTOMERGROUP,ROLE_PRONTO,western service\""]

```

the problem if i use a standard aggregation on the field roles, elasticsearch will split " western service " :

```
"aggregations": {
"roles": {
  "doc_count_error_upper_bound": 0,
  "sum_other_doc_count": 0,
  "buckets": [
    {
      "key": "role_customergroup",
      "doc_count": 3124
    },
               {
      "key": "role_pronto",
      "doc_count": 1945
    },
    {
      "key": "role_rustic",
      "doc_count": 1179
    },
    {
      "key": "role_services",
      "doc_count": 1179
    },
    {
      "key": "services",
      "doc_count": 1179
    },
    {
      "key": "west",
      "doc_count": 1179
    }
  ]
}

```

is there any solotion to this problem? should i use a script?

Thank you !

---

<div class="post-metadata">

### Author: ![litalk](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@litalk](https://discuss.elastic.co/u/litalk)
#### Post date: [May 2, 2016, 12:38pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-split-a-field/48555/2 "2016-05-02T12:38:00Z")

</div>

This is because of the analyzer, if you don't want elastic search to "break" the words on that field you should set "roles" field to be not\_analyzed.

---

<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, 10:54pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-split-a-field/48555/3 "2017-07-05T22:54:42Z")

</div>


