# Removing occurrences of repeated text Characters from title in Elastic cloud

**URL:** <https://discuss.elastic.co/t/removing-occurrences-of-repeated-text-characters-from-title-in-elastic-cloud/369775>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [October 30, 2024, 3:39am UTC](https://discuss.elastic.co/t/removing-occurrences-of-repeated-text-characters-from-title-in-elastic-cloud/369775 "2024-10-30T03:39:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidT\_Spark](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DavidT\_Spark](https://discuss.elastic.co/u/DavidT_Spark)\
**Post date:** [October 30, 2024, 3:39am UTC](https://discuss.elastic.co/t/removing-occurrences-of-repeated-text-characters-from-title-in-elastic-cloud/369775/1 "2024-10-30T03:39:35Z")

</div>

I would like to remove any "| Brand" occurrences in the title field in such results.

What script should I use?

I tried painless scripts

String title = doc['title'].value;  
if (title != null) {  
// Use replaceAll to remove all occurrences of "| abc def"  
return title.replaceAll('\|\s_abc\s_def', '');  
}  
return ''; // Return an empty string if title is null

But I think the logic is incorrect.

Let me know if I should use use Kibana, ingestion API or anything else, I'm not a dev, but I do know how to get around the platform, so do need some step instructions.

---

<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:** [October 30, 2024, 5:55am UTC](https://discuss.elastic.co/t/removing-occurrences-of-repeated-text-characters-from-title-in-elastic-cloud/369775/2 "2024-10-30T05:55:17Z")

</div>

I'd run that script at index time using a [Script Processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/script-processor.html) in an ingest pipeline.  
Or a [gsub processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/gsub-processor.html).

---

<div class="post-metadata">

**Author:** ![DavidT\_Spark](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DavidT\_Spark](https://discuss.elastic.co/u/DavidT_Spark)\
**Post date:** [October 30, 2024, 6:05am UTC](https://discuss.elastic.co/t/removing-occurrences-of-repeated-text-characters-from-title-in-elastic-cloud/369775/3 "2024-10-30T06:05:53Z")

</div>

Is my script correct?

---

<div class="post-metadata">

**Author:** ![thiagodsrodrigues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiagodsrodrigues/32/133778_2.png) [@thiagodsrodrigues](https://discuss.elastic.co/u/thiagodsrodrigues)\
**Post date:** [October 30, 2024, 7:47am UTC](https://discuss.elastic.co/t/removing-occurrences-of-repeated-text-characters-from-title-in-elastic-cloud/369775/5 "2024-10-30T07:47:57Z")

</div>

To remove occurrences of "|Brand" from the title field in Elasticsearch, you can use a Painless script.

---

<div class="post-metadata">

**Author:** ![DavidT\_Spark](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DavidT\_Spark](https://discuss.elastic.co/u/DavidT_Spark)\
**Post date:** [October 31, 2024, 12:17am UTC](https://discuss.elastic.co/t/removing-occurrences-of-repeated-text-characters-from-title-in-elastic-cloud/369775/6 "2024-10-31T00:17:56Z")

</div>

Yes, but where will I need to place the script?

I tried painless String title = doc['title'].value;  
if (title != null) {  
// Use replaceAll to remove all occurrences of "| Brand AB"  
return title.replaceAll('|\sBrand\sAB', '');  
}  
return ''; // Return an empty string if title is null

I'm not a dev, so need some guidence
