# How to count values of fields names with same prefix?

**URL:** https://discuss.elastic.co/t/how-to-count-values-of-fields-names-with-same-prefix/87641
**Category:** Elasticsearch
**Created:** [May 30, 2017, 9:54pm UTC](https://discuss.elastic.co/t/how-to-count-values-of-fields-names-with-same-prefix/87641 "2017-05-30T21:54:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Rodrigo\_Tornis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_tornis/32/18015_2.png) [@Rodrigo\_Tornis](https://discuss.elastic.co/u/Rodrigo_Tornis)
#### Post date: [May 30, 2017, 9:54pm UTC](https://discuss.elastic.co/t/how-to-count-values-of-fields-names-with-same-prefix/87641/1 "2017-05-30T21:54:28Z")

</div>

Hello guys,

I need to create a script field that counts values of fields with the same prefix:

SMF\_001, SMF\_002 ... SMF\_300

How can I painlessly go through these fields? I imagine something like:

```
for (int i = 0; i <300; i ++) {
val = val + doc ['SMF_' + i] .value;
}

```

It is possible?

Thank you

---

<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: [June 27, 2017, 9:54pm UTC](https://discuss.elastic.co/t/how-to-count-values-of-fields-names-with-same-prefix/87641/2 "2017-06-27T21:54:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
