# Creating Scripted field by extracting filename from long log message

**URL:** <https://discuss.elastic.co/t/creating-scripted-field-by-extracting-filename-from-long-log-message/235227>\
**Category:** Elasticsearch\
**Created:** [June 1, 2020, 8:32pm UTC](https://discuss.elastic.co/t/creating-scripted-field-by-extracting-filename-from-long-log-message/235227 "2020-06-01T20:32:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarvendras](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sarvendras/32/46287_2.png) [@sarvendras](https://discuss.elastic.co/u/sarvendras)\
**Post date:** [June 1, 2020, 8:32pm UTC](https://discuss.elastic.co/t/creating-scripted-field-by-extracting-filename-from-long-log-message/235227/1 "2020-06-01T20:32:59Z")

</div>

HI team,  
I have to extract substring(some file name) from long log message in a index.  
I am trying toi create a scripted filed for extracting substring(file name) from long file using below painless script but its not giving any filename infact lank value coming.

Example-  
log\_text-20200323SSWaterfallTran20.csvFile Uploaded for sourcecisoAccuireblanksource1

I have to create new scripted field in index with value as -20200323SSWaterfallTran20

painless script using:  
def m = /.\*csv/.matcher(doc["log"].value); if ( m.matches() ) { return m.group(1) } else { return"" }

Thanks  
Sarvendra

---

<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 29, 2020, 8:33pm UTC](https://discuss.elastic.co/t/creating-scripted-field-by-extracting-filename-from-long-log-message/235227/2 "2020-06-29T20:33:06Z")

</div>

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