# Trouble dissecting characters from a word in a string

**URL:** <https://discuss.elastic.co/t/trouble-dissecting-characters-from-a-word-in-a-string/284924>\
**Category:** Beats\
**Tags:** filebeat, metricbeat\
**Created:** [September 22, 2021, 6:15pm UTC](https://discuss.elastic.co/t/trouble-dissecting-characters-from-a-word-in-a-string/284924 "2021-09-22T18:15:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticperson](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@elasticperson](https://discuss.elastic.co/u/elasticperson)\
**Post date:** [September 22, 2021, 6:15pm UTC](https://discuss.elastic.co/t/trouble-dissecting-characters-from-a-word-in-a-string/284924/1 "2021-09-22T18:15:42Z")

</div>

Example strings:  
thing: xabc123def.testing  
thing: xghi456jkl.testing

Given:

- String will always begin with x
- there will be 3 alpha characters
- there will be 3 numeric characters
- it may or may not have additional characters after.

I need to extra the first 3 alpha characters (after x) into a new field using a metric/filebeat processor (dissect)

Obviously this will not work:

- dissect:  
tokenizer: "x%{item1}%{?first number}  
field: "extractedfield"

I couldn't find any info on dissect/tokenizer relating to individual characters or wildcards. For example, if I could say make item1 3 characters long, the rest would be easy. Or if I could use a wild card for any number, I could use that as the delimiter.

---

<div class="post-metadata">

**Author:** ![e997cd7e8d9915436150](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/e997cd7e8d9915436150/32/40255_2.png) [@e997cd7e8d9915436150](https://discuss.elastic.co/u/e997cd7e8d9915436150)\
**Post date:** [September 23, 2021, 4:25am UTC](https://discuss.elastic.co/t/trouble-dissecting-characters-from-a-word-in-a-string/284924/2 "2021-09-23T04:25:51Z")

</div>

Grok is the best way when no separator like example.  
But filebeat has no grok processor unfortunately.  
Given strings, i think script processor is best way.

```auto
  - script:
      lang: javascript
      source: >
        function process(event) {
          var str1 = event.Get("extractedfield");
          var str2 = str1.substr(1,3);
          event.Put("item1", str2);
        }

```

---

<div class="post-metadata">

**Author:** ![elasticperson](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@elasticperson](https://discuss.elastic.co/u/elasticperson)\
**Post date:** [September 23, 2021, 3:38pm UTC](https://discuss.elastic.co/t/trouble-dissecting-characters-from-a-word-in-a-string/284924/3 "2021-09-23T15:38:36Z")

</div>

Wow thank you. I was aware that I couldn't do grok in processors but I was unaware of the script processor.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 29, 2021, 1:06am UTC](https://discuss.elastic.co/t/trouble-dissecting-characters-from-a-word-in-a-string/284924/4 "2021-09-29T01:06:45Z")

</div>

The alternative here would be to use an ingest pipeline in Elasticsearch, which has grok.

---

<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:** [October 27, 2021, 3:07am UTC](https://discuss.elastic.co/t/trouble-dissecting-characters-from-a-word-in-a-string/284924/5 "2021-10-27T03:07:37Z")

</div>

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