AntonShuvaev / elasticsearch4idea

Elasticsearch Plugin for JetBrains IDEs
https://plugins.jetbrains.com/plugin/14512-elasticsearch
58 stars 8 forks source link

Console does not support multi-line or auto escaping #113

Closed lookingcloudy closed 1 year ago

lookingcloudy commented 1 year ago

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:

AntonShuvaev commented 1 year ago

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?

lookingcloudy commented 1 year ago

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    "
  }
}
AntonShuvaev commented 1 year ago

Can you try to replace this double quotes “ with this double quotes " ?

lookingcloudy commented 1 year ago

Good eye - I didn't notice the different character. This works.