Skip to content

Conversation

luigidellaquila
Copy link
Contributor

@luigidellaquila luigidellaquila commented Oct 22, 2024

Escaping special characters in strings is complex.
Escaping them in regex is painful.
We can make user's life easier by suggesting to use triple quotes strings in commands and operators that will likely contain special characters (GROK, DISSECT, LIKE, RLIKE). This will significantly reduce the number of escapes needed.

eg.

ROW field = """foo [bar\\baz]""" | GROK field "foo \\[%{WORD:x}\\\\%{WORD:y}\\]"

vs

ROW field = """foo [bar\\baz]""" | GROK field """foo \[%{WORD:x}\\%{WORD:y}\]"""

or for the typical Windows paths:

| GROK field "C:\\\\my\\\\folder\\\\and\\\\%{WORD:file}\\.exe"

vs

| GROK field """C:\\my\\folder\\and\\%{WORD:file}\.exe"""

This PR enchances the docs for all the operators/commands mentioned above:

  • adding triple quotes """ in all the sample queries
  • explicitly mentioning escaping and suggesting to always use triple quotes

Fixes: #115051

@luigidellaquila luigidellaquila added >docs General docs changes auto-backport Automatically create backport pull requests when merged v8.15.4 v8.16.1 v8.17.0 labels Oct 22, 2024
Copy link
Contributor

Documentation preview:

@luigidellaquila
Copy link
Contributor Author

@elasticmachine update branch

@luigidellaquila
Copy link
Contributor Author

@elasticmachine update branch

@luigidellaquila
Copy link
Contributor Author

@elasticmachine update branch

@luigidellaquila luigidellaquila marked this pull request as ready for review October 23, 2024 12:57
@elasticsearchmachine elasticsearchmachine added Team:Docs Meta label for docs team Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) labels Oct 23, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-docs (Team:Docs)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only note that in some cases we only give triple quotes examples, it might be good to keep some simple ones too. But LGTM.

@luigidellaquila
Copy link
Contributor Author

I'd only note that in some cases we only give triple quotes examples

Yeah, it's a bit extreme 😅
But the intention is to set triple quotes as a standard for regex-like strings, to avoid problems when they become more complex

@luigidellaquila luigidellaquila merged commit bffaabb into elastic:main Oct 24, 2024
15 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.15 Commit could not be cherrypicked due to conflicts
8.16
8.x

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 115320

luigidellaquila added a commit to luigidellaquila/elasticsearch that referenced this pull request Oct 24, 2024
luigidellaquila added a commit to luigidellaquila/elasticsearch that referenced this pull request Oct 24, 2024
luigidellaquila added a commit to luigidellaquila/elasticsearch that referenced this pull request Oct 24, 2024
davidkyle pushed a commit to davidkyle/elasticsearch that referenced this pull request Oct 24, 2024
georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Oct 25, 2024
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged backport pending >docs General docs changes Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:Docs Meta label for docs team v8.15.4 v8.16.1 v8.17.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESQL: Add example with triple-quotes under grok and dissect for easy escaping

5 participants