Replace string in a string field (Ingest Pipeline)

I have a field for which I would need to replace 
 values by CrLf.
I tried the following but \r\n is not recognized (unexpected character [\"\\r]. The only valid escape sequences in strings starting with [\"] are [\\\\] and [\\\"].).
The only way I found to get somewhere similar is by literally creating a new line in my script but even then, it create a \n value instead of \r\n (or at least it seems according to further manipulations).

{
	"script": {
	  "lang": "painless",
	  "source": """
		if(ctx.group?.MyField != null)
		  ctx.group.MyField.replace("
", "\r\n");
		"""
	}
}

the replace function returns a value, but does not do an in-place replacement. So you need to assign a variable to the result (likely ctx.group.MyField = ...)

You are right, I did modify my code in that sens but forgot to change it here. But the problem is still with the string escaping in an ingest painless script.

Do you have a complete Simulate pipeline API one could try and reproduce locally?

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