# Create Scripted Field using substring before "."

**URL:** <https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096>\
**Category:** Kibana\
**Created:** [June 22, 2020, 1:45pm UTC](https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096 "2020-06-22T13:45:32Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![giacman](https://avatars.discourse-cdn.com/v4/letter/g/f07891/32.png) [@giacman](https://discuss.elastic.co/u/giacman)\
**Post date:** [June 22, 2020, 2:03pm UTC](https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096/3 "2020-06-22T14:03:58Z")

</div>

Hi Aaron,

thanks a lot for your quick reply.

I get this error "Unable to write index pattern! Refresh the page to get the most up to date changes for this index pattern." and the Create Field object keeps spinning.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/6/b6592f1b6600bde1f9b0026966664b14f06cfa9e.png)

I have also found theses articles that seems similar:

> [@Scripted Field: getting first index of a substring](https://discuss.elastic.co/t/scripted-field-getting-first-index-of-a-substring/81418/2):
>
> I'm not a painless expert, but [here is the API](https://www.elastic.co/guide/en/elasticsearch/reference/current/painless-api-reference.html). You already know the index of the last / from the use of lastIndexOf, and you're already using substring. If you give [substring](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#substring%2Dint%2Dint%2D) 2 arguments, it'll use the first one as the start and the last one as the end, non-inclusive. So, in your case, this should give you the content before the last / - return path.substring(0, lastSlashIndex); def path = doc['string\_value.keyword'].value; if (path != null) { int lastSlashIndex = path.lastIndexOf('/'); if (…

> [@ScriptedField - Only part before comma is taken](https://discuss.elastic.co/t/scriptedfield-only-part-before-comma-is-taken/85885):
>
> I added a scripted field to my index with name Drift using painless: Name Language Script Drift painless doc['NumberValue'].value The attribute NumberValue has float values. The scripted field shows only the part before the comma [image] When I do the same with another float attribute the scripted field shows the hole float number. How can I troubleshoot this error? Thank you for your support

But I couldn't make it work. Any help would be greatly appreciated!

---

_[View the full topic](https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096)._
