# How to escape colon in painless

**URL:** <https://discuss.elastic.co/t/how-to-escape-colon-in-painless/299328>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [March 10, 2022, 11:11am UTC](https://discuss.elastic.co/t/how-to-escape-colon-in-painless/299328 "2022-03-10T11:11:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![geppo](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@geppo](https://discuss.elastic.co/u/geppo)\
**Post date:** [March 10, 2022, 11:11am UTC](https://discuss.elastic.co/t/how-to-escape-colon-in-painless/299328/1 "2022-03-10T11:11:38Z")

</div>

Hi to everyone!

Few days ago someone in my company has created in my cluster a field called `total_chunks.RS|24|12:24` and I would like to rename It with an `update_by_query`.

I have tried this query:

```auto

{
  "query": { 
    "bool": {
        "must": {
            "exists": {
                "field": "body.total_chunks.RS|24|12:24"
            }
        }
    }
  },
  "script" : {
    "inline": """ ctx._source.body.total_chunks.RS_24_12_24 = ctx._source.body.total_chunks.RS|24|12:24; \n ctx._source.remove(\"body.total_chunks.RS|24|12:24\");"""
  }
}

```

And returns to me this error:

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "... ody.total_chunks.RS|24|12:24; \\n ctx._source.remov ...",
          " ^---- HERE"
        ],
        "script" : " ctx._source.body.total_chunks.RS_24_12_24 = ctx._source.body.total_chunks.RS|24|12:24; \\n ctx._source.remove(\\\"body.total_chunks.RS|24|12:24\\\");",
        "lang" : "painless",
        "position" : {
          "offset" : 83,
          "start" : 58,
          "end" : 108
        }
      }
    ],
    "type" : "script_exception",
    "reason" : "compile error",
    "script_stack" : [
      "... ody.total_chunks.RS|24|12:24; \\n ctx._source.remov ...",
      " ^---- HERE"
    ],
    "script" : " ctx._source.body.total_chunks.RS_24_12_24 = ctx._source.body.total_chunks.RS|24|12:24; \\n ctx._source.remove(\\\"body.total_chunks.RS|24|12:24\\\");",
    "lang" : "painless",
    "position" : {
      "offset" : 83,
      "start" : 58,
      "end" : 108
    },
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "unexpected token [':'] was expecting one of [{<EOF>, ';'}]."
    }
  },
  "status" : 400
}

```

So I thought to escape colon, but if I insert a backslash, another error occurs:

This is the inline script with the escaped colon  
`""" ctx._source.body.total_chunks.RS_24_12_24 = ctx._source.body.total_chunks.RS|24|12\:24; \n ctx._source.remove(\"body.total_chunks.RS|24|12:24\");"""`

And this is the new error, that says that backslash was unexpected:

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "... ody.total_chunks.RS|24|12\\:24; \\n ctx._source.remo ...",
          " ^---- HERE"
        ],
        "script" : " ctx._source.body.total_chunks.RS_24_12_24 = ctx._source.body.total_chunks.RS|24|12\\:24; \\n ctx._source.remove(\\\"body.total_chunks.RS|24|12:24\\\");",
        "lang" : "painless",
        "position" : {
          "offset" : 83,
          "start" : 58,
          "end" : 108
        }
      }
    ],
    "type" : "script_exception",
    "reason" : "compile error",
    "script_stack" : [
      "... ody.total_chunks.RS|24|12\\:24; \\n ctx._source.remo ...",
      " ^---- HERE"
    ],
    "script" : " ctx._source.body.total_chunks.RS_24_12_24 = ctx._source.body.total_chunks.RS|24|12\\:24; \\n ctx._source.remove(\\\"body.total_chunks.RS|24|12:24\\\");",
    "lang" : "painless",
    "position" : {
      "offset" : 83,
      "start" : 58,
      "end" : 108
    },
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "unexpected character [\\].",
      "caused_by" : {
        "type" : "lexer_no_viable_alt_exception",
        "reason" : null
      }
    }
  },
  "status" : 400
}

```

What I'm doing wrong here?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [March 10, 2022, 1:42pm UTC](https://discuss.elastic.co/t/how-to-escape-colon-in-painless/299328/2 "2022-03-10T13:42:01Z")

</div>

I tried it also and not sure what's going on with the `:`. But you can do this using an ingest processor like so.

```auto
DELETE testcolon

PUT testcolon

POST testcolon/_doc
{
  "total_chunks.RS|24|12:24": "test"
}

PUT _ingest/pipeline/colon
{
  "processors": [
    {
      "dot_expander": {
        "field": "total_chunks.RS|24|12:24"
      }
    },
    {
      "rename": {
        "field": "total_chunks.RS|24|12:24",
        "target_field": "total_chunks_RS_24_12_24"
      }
    },
    {
      "remove": {
        "field": "total_chunks"
      }
    }
  ]
}

POST testcolon/_update_by_query?pipeline=colon

GET testcolon/_search

```

**Results**

```auto
"_source" : {
  "total_chunks_RS_24_12_24" : "test"
}

```

---

<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:** [April 7, 2022, 1:42pm UTC](https://discuss.elastic.co/t/how-to-escape-colon-in-painless/299328/3 "2022-04-07T13:42:26Z")

</div>

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