Console does not support multi-line or auto escaping
lookingcloudy opened this issue · comments
Describe the bug
The console should at least have parity with the Kibana dev tools. Kibana dev tools supports
triple-quoting script text, which automatically escapes embedded quotes and supports multi-line.
In addition, I cannot simply copy such a request from Kibana dev tools to the query console due to the lack of multi-line support.
Steps to reproduce
POST _reindex?wait_for_completion=true
{
"source": {
"index": "requestlog",
"query": {
"match": {
"_id": "ea799763-7bd7-4b81-9476-865ae4da9a0b"
}
}
},
"dest": {
"index": "prod-requestlogs",
"pipeline": "requestlogs-reindex"
},
"script": {
"lang": "painless",
"source": """
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy_MM”);
ZonedDateTime createdAt = ZonedDateTime.parse(ctx._source.createdAt);
String output = createdAt.format(formatter);
ctx._index = ‘prod-requestlogs-’ + output
"""
}
}
Expected behavior
Should support triple quoting. At a minimum should support multi-line without triple quoting.
Environment information:
- OS: Ventura 13.4
- IDE version: Datagrip 2023.1.2
- plugin version: 2023.2.3
- Elasticsearch or OpenSearch version:
I've tested triple quoting on request
POST test/_doc
{
"test": """
"a": 'a'
"""
}
and it works correctly. Could you please specify the exact error message you're encountering?
Here is the request that failed:
POST _reindex?wait_for_completion=true
{
"source": {
"index": "prod-dbo-requestlog",
"query": {
"match": {
"_id": "ea799763-7bd7-4b81-9476-865ae4da9a0b"
}
}
},
"dest": {
"index": "prod-triton-requestlogs",
"pipeline": "triton-requestlogs-reindex"
},
"script": {
"lang": "painless",
"source": """
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy_MM”);
ZonedDateTime createdAt = ZonedDateTime.parse(ctx._source.createdAt);
String output = createdAt.format(formatter);
ctx._index = "prod-triton-requestlogs-" + output
"""
}
}
And here is the error:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... eTimeFormatter.ofPattern(“yyyy_MM”);\n Zoned ...",
" ^---- HERE"
],
"script": "\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy_MM”);\n ZonedDateTime createdAt = ZonedDateTime.parse(ctx._source.createdAt);\n String output = createdAt.format(formatter);\n ctx._index = \"prod-triton-requestlogs-\" + output\n ",
"lang": "painless",
"position": {
"offset": 67,
"start": 42,
"end": 92
}
}
],
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... eTimeFormatter.ofPattern(“yyyy_MM”);\n Zoned ...",
" ^---- HERE"
],
"script": "\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy_MM”);\n ZonedDateTime createdAt = ZonedDateTime.parse(ctx._source.createdAt);\n String output = createdAt.format(formatter);\n ctx._index = \"prod-triton-requestlogs-\" + output\n ",
"lang": "painless",
"position": {
"offset": 67,
"start": 42,
"end": 92
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "unexpected character [“].",
"caused_by": {
"type": "lexer_no_viable_alt_exception",
"reason": null
}
}
},
"status": 400
}
This version works - concatenated and quoted manually.
POST _reindex?wait_for_completion=true
{
"source": {
"index": "prod-dbo-requestlog",
"query": {
"match": {
"_id": "ea799763-7bd7-4b81-9476-865ae4da9a0b"
}
}
},
"dest": {
"index": "prod-triton-requestlogs",
"pipeline": "triton-requestlogs-reindex"
},
"script": {
"lang": "painless",
"source": "DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"yyyy_MM\");ZonedDateTime createdAt = ZonedDateTime.parse(ctx._source.createdAt);String output = createdAt.format(formatter);ctx._index = \"prod-triton-requestlogs-\" + output "
}
}
Can you try to replace this double quotes “ with this double quotes " ?
Good eye - I didn't notice the different character. This works.