# Aggregations over fields which have multiple words in them

**URL:** <https://discuss.elastic.co/t/aggregations-over-fields-which-have-multiple-words-in-them/18456>\
**Category:** Elasticsearch\
**Created:** [July 3, 2014, 7:47am UTC](https://discuss.elastic.co/t/aggregations-over-fields-which-have-multiple-words-in-them/18456 "2014-07-03T07:47:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankit\_Jain\_2](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@Ankit\_Jain\_2](https://discuss.elastic.co/u/Ankit_Jain_2)\
**Post date:** [July 3, 2014, 7:47am UTC](https://discuss.elastic.co/t/aggregations-over-fields-which-have-multiple-words-in-them/18456/1 "2014-07-03T07:47:06Z")

</div>

Hey Folks, how do I do aggregations on a multi word field? i.e. if i have a  
field named "device model" which could have "samsung galaxy s5" or "iphone  
5s" when I do an aggregation, it aggregates "samsung" separately from  
"galaxy" separately from "s5"... ideas?

I tried defining the index with a mapping where that field has index :  
not\_analyzed set...

Thanks in advance,  
Ankit!

--  
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/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 3, 2014, 8:07am UTC](https://discuss.elastic.co/t/aggregations-over-fields-which-have-multiple-words-in-them/18456/2 "2014-07-03T08:07:08Z")

</div>

Yes. Using not\_analyzed is the way to go.  
May be you could create a SENSE script and gist it so we can see what you did wrong?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 3 juil. 2014 à 09:47, Ankit Jain [ankit@quettra.com](mailto:ankit@quettra.com) a écrit :

Hey Folks, how do I do aggregations on a multi word field? i.e. if i have a field named "device model" which could have "samsung galaxy s5" or "iphone 5s" when I do an aggregation, it aggregates "samsung" separately from "galaxy" separately from "s5"... ideas?

I tried defining the index with a mapping where that field has index : not\_analyzed set...

## Thanks in advance, Ankit!

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/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com).  
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/91A4A108-9FAD-46BD-A485-C3BC5903FDC9%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/91A4A108-9FAD-46BD-A485-C3BC5903FDC9%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ankit\_Jain\_2](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@Ankit\_Jain\_2](https://discuss.elastic.co/u/Ankit_Jain_2)\
**Post date:** [July 3, 2014, 4:47pm UTC](https://discuss.elastic.co/t/aggregations-over-fields-which-have-multiple-words-in-them/18456/3 "2014-07-03T16:47:47Z")

</div>

Not sure what a SENSE script is but below is how to reproduce this. Let me  
know if this makes sense.

Thank you for helping.

-Ankit

ankit$ curl -XPUT [http://localhost:9200/test](http://localhost:9200/test) -d '"mappings": { "test": {  
"properties": { "deviceId": { "type": "string", "index": "not\_analyzed" },  
"basics": { "type": "nested", "properties": { "sex": { "type": "string",  
"index": "not\_analyzed" }, "device": { "type": "string", "index":  
"not\_analyzed" } } } } } } }'

{"acknowledged":true}

ankit$ curl -XPUT '[http://localhost:9200/test/test/1](http://localhost:9200/test/test/1)' -d '{ "basics": {  
"sex": "m", "device": "LGE LG-P768" }, "deviceId": "1" }'

{"\_index":"test","\_type":"test","\_id":"1","\_version":1,"created":true}

ankit$ curl -XPUT '[http://localhost:9200/test/test/2](http://localhost:9200/test/test/2)' -d '{ "basics": {  
"sex": "m", "device": "Samsung SHW-M250S" }, "deviceId": "2" }'

{"\_index":"test","\_type":"test","\_id":"2","\_version":1,"created":true}

ankit$ curl -XGET  
'[http://localhost:9200/test/test/\_search?search\_type=count&pretty](http://localhost:9200/test/test/_search?search_type=count&pretty)' -d '{  
"aggregations": { "popular\_devices": { "terms": { "field": "device" } } } }'

{

"took" : 2,

"timed\_out" : false,

"\_shards" : {

```
"total" : 5,

"successful" : 5,

"failed" : 0

```

},

"hits" : {

```
"total" : 2,

"max_score" : 0.0,

"hits" : []

```

},

"aggregations" : {

```
"popular_devices" : {

  "buckets" : [ {

    "key" : "lg",

    "doc_count" : 1

  }, {

    "key" : "lge",

    "doc_count" : 1

  }, {

    "key" : "m250s",

    "doc_count" : 1

  }, {

    "key" : "p768",

    "doc_count" : 1

  }, {

    "key" : "samsung",

    "doc_count" : 1

  }, {

    "key" : "shw",

    "doc_count" : 1

  } ]

}

```

}

}

On Thursday, July 3, 2014 1:08:13 AM UTC-7, David Pilato wrote:

> Yes. Using not\_analyzed is the way to go.  
> May be you could create a SENSE script and gist it so we can see what you  
> did wrong?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 3 juil. 2014 à 09:47, Ankit Jain \<[an...@quettra.com](mailto:an...@quettra.com) \<javascript:\>\> a  
> écrit :
> 
> Hey Folks, how do I do aggregations on a multi word field? i.e. if i have  
> a field named "device model" which could have "samsung galaxy s5" or  
> "iphone 5s" when I do an aggregation, it aggregates "samsung" separately  
> from "galaxy" separately from "s5"... ideas?
> 
> I tried defining the index with a mapping where that field has index :  
> not\_analyzed set...
> 
> Thanks in advance,  
> Ankit!
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/433ae04a-73b4-462d-9be0-d5f20ff6c42f%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/bbf49792-7f19-4359-b53f-860d8ddb16b7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bbf49792-7f19-4359-b53f-860d8ddb16b7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 3, 2014, 5:52pm UTC](https://discuss.elastic.co/t/aggregations-over-fields-which-have-multiple-words-in-them/18456/4 "2014-07-03T17:52:12Z")

</div>

Strange.

Your script does not work on my end.  
I think it's may be because you already have a test index before starting your test???

Actually, I did not get any bucket as an answer.

And that's normal to me as you defined a nested doc.

This script works fine for me: [https://gist.github.com/dadoonet/a04013991566b8a5ec39](https://gist.github.com/dadoonet/a04013991566b8a5ec39)

It gives:

{  
"took": 7,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 2,  
"max\_score": 0,  
"hits": []  
},  
"aggregations": {  
"popular\_devices": {  
"buckets": [  
{  
"key": "LGE LG-P768",  
"doc\_count": 1  
},  
{  
"key": "Samsung SHW-M250S",  
"doc\_count": 1  
}  
]  
}  
}  
}

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 3 juillet 2014 à 18:47:51, Ankit Jain ([ankit@quettra.com](mailto:ankit@quettra.com)) a écrit:

Not sure what a SENSE script is but below is how to reproduce this. Let me know if this makes sense.

Thank you for helping.

-Ankit

ankit$ curl -XPUT [http://localhost:9200/test](http://localhost:9200/test) -d '"mappings": { "test": { "properties": { "deviceId": { "type": "string", "index": "not\_analyzed" }, "basics": { "type": "nested", "properties": { "sex": { "type": "string", "index": "not\_analyzed" }, "device": { "type": "string", "index": "not\_analyzed" } } } } } } }'

{"acknowledged":true}

ankit$ curl -XPUT '[http://localhost:9200/test/test/1](http://localhost:9200/test/test/1)' -d '{ "basics": { "sex": "m", "device": "LGE LG-P768" }, "deviceId": "1" }'

{"\_index":"test","\_type":"test","\_id":"1","\_version":1,"created":true}

ankit$ curl -XPUT '[http://localhost:9200/test/test/2](http://localhost:9200/test/test/2)' -d '{ "basics": { "sex": "m", "device": "Samsung SHW-M250S" }, "deviceId": "2" }'

{"\_index":"test","\_type":"test","\_id":"2","\_version":1,"created":true}

ankit$ curl -XGET '[http://localhost:9200/test/test/\_search?search\_type=count&pretty](http://localhost:9200/test/test/_search?search_type=count&pretty)' -d '{ "aggregations": { "popular\_devices": { "terms": { "field": "device" } } } }'

{

"took" : 2,

"timed\_out" : false,

"\_shards" : {

```
"total" : 5,

"successful" : 5,

"failed" : 0

```

},

"hits" : {

```
"total" : 2,

"max_score" : 0.0,

"hits" : []

```

},

"aggregations" : {

```
"popular_devices" : {

  "buckets" : [ {

    "key" : "lg",

    "doc_count" : 1

  }, {

    "key" : "lge",

    "doc_count" : 1

  }, {

    "key" : "m250s",

    "doc_count" : 1

  }, {

    "key" : "p768",

    "doc_count" : 1

  }, {

    "key" : "samsung",

    "doc_count" : 1

  }, {

    "key" : "shw",

    "doc_count" : 1

  } ]

}

```

}

}

On Thursday, July 3, 2014 1:08:13 AM UTC-7, David Pilato wrote:  
Yes. Using not\_analyzed is the way to go.  
May be you could create a SENSE script and gist it so we can see what you did wrong?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 3 juil. 2014 à 09:47, Ankit Jain [an...@quettra.com](mailto:an...@quettra.com) a écrit :

Hey Folks, how do I do aggregations on a multi word field? i.e. if i have a field named "device model" which could have "samsung galaxy s5" or "iphone 5s" when I do an aggregation, it aggregates "samsung" separately from "galaxy" separately from "s5"... ideas?

I tried defining the index with a mapping where that field has index : not\_analyzed set...

## Thanks in advance, Ankit!

## 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com). To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/433ae04a-73b4-462d-9be0-d5f20ff6c42f%40googlegroups.com). 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/bbf49792-7f19-4359-b53f-860d8ddb16b7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bbf49792-7f19-4359-b53f-860d8ddb16b7%40googlegroups.com).  
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/etPan.53b5984c.2d1d5ae9.cc4%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53b5984c.2d1d5ae9.cc4%40MacBook-Air-de-David.local).  
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:18am UTC](https://discuss.elastic.co/t/aggregations-over-fields-which-have-multiple-words-in-them/18456/5 "2017-07-06T01:18:03Z")

</div>


