---
setup:
- skip:
    awaits_fix: "waiting for final decisions on supporting generic expressions on\
      \ the right https://github.com/elastic/elasticsearch/issues/103599"
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    test_runner_features: "allowed_warnings_regex"
- do:
    indices.create:
      index: "test"
      body:
        mappings:
          properties:
            id:
              type: "long"
            keyword:
              type: "keyword"
            keywordUpper:
              type: "keyword"
            text:
              type: "text"
            textCamel:
              type: "text"
            wildcard:
              type: "keyword"
            wildcardText:
              type: "text"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "test"
      refresh: true
      body:
      - index: {}
      - id: 0
        keyword: "Foo"
        keywordUpper: "FOO"
        text: "foo"
        textCamel: "FoO"
        wildcard: "Foo*"
        wildcardText: "FOo*"
      - index: {}
      - id: 1
        keyword: "Foo"
        keywordUpper: "BAR"
        text: "baz"
        textCamel: "BaR"
        wildcard: "Bar?"
        wildcardText: "bar?"
      - index: {}
      - id: 2
        keyword: "abc"
        keywordUpper: "XYZ"
        text: "def"
        textCamel: "GhI"
        wildcard: "jkl?"
        wildcardText: "MNO?"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
insensitive equals field vs field keywords:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where keyword =~ keywordUpper | keep id, keyword, keywordUpper"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "keyword"
- match:
    columns.1.type: "keyword"
- match:
    columns.2.name: "keywordUpper"
- match:
    columns.2.type: "keyword"
- length:
    values: 1
- match:
    values.0:
    - 0
    - "Foo"
    - "FOO"
---
insensitive equals field vs field text:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where text =~ textCamel | keep id, text, textCamel"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "text"
- match:
    columns.1.type: "text"
- match:
    columns.2.name: "textCamel"
- match:
    columns.2.type: "text"
- length:
    values: 1
- match:
    values.0:
    - 0
    - "foo"
    - "FoO"
---
insensitive equals keyword field vs text field:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where keyword =~ text | keep id, keyword, text"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "keyword"
- match:
    columns.1.type: "keyword"
- match:
    columns.2.name: "text"
- match:
    columns.2.type: "text"
- length:
    values: 1
- match:
    values.0:
    - 0
    - "Foo"
    - "foo"
---
insensitive equals keyword field vs text field 2:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where keywordUpper =~ textCamel | keep id, keywordUpper,\
          \ textCamel | sort id"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "keywordUpper"
- match:
    columns.1.type: "keyword"
- match:
    columns.2.name: "textCamel"
- match:
    columns.2.type: "text"
- length:
    values: 2
- match:
    values.0:
    - 0
    - "FOO"
    - "FoO"
- match:
    values.1:
    - 1
    - "BAR"
    - "BaR"
---
wildcards:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where keywordUpper =~ \"fo*\" | keep id, keywordUpper"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "keywordUpper"
- match:
    columns.1.type: "keyword"
- length:
    values: 0
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where wildcard =~ \"foo*\" | keep id, wildcard"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "wildcard"
- match:
    columns.1.type: "keyword"
- length:
    values: 1
- match:
    values.0:
    - 0
    - "Foo*"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where wildcard =~ \"fOo*\" | keep id, wildcard"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "wildcard"
- match:
    columns.1.type: "keyword"
- length:
    values: 1
- match:
    values.0:
    - 0
    - "Foo*"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where keywordUpper =~ \"fo?\" | keep id, keywordUpper"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "keywordUpper"
- match:
    columns.1.type: "keyword"
- length:
    values: 0
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where wildcard =~ \"bar?\" | keep id, wildcard"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "wildcard"
- match:
    columns.1.type: "keyword"
- length:
    values: 1
- match:
    values.0:
    - 1
    - "Bar?"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where wildcard =~ \"bAr?\" | keep id, wildcard"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "wildcard"
- match:
    columns.1.type: "keyword"
- length:
    values: 1
- match:
    values.0:
    - 1
    - "Bar?"
---
wildcards on text:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where text =~ \"Fo*\" | keep id, text | sort id"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "text"
- match:
    columns.1.type: "text"
- length:
    values: 0
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where wildcardText =~ \"fOo*\" | keep id, wildcardText"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "wildcardText"
- match:
    columns.1.type: "text"
- length:
    values: 1
- match:
    values.0:
    - 0
    - "FOo*"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where wildcardText =~ \"bAr?\" | keep id, wildcardText"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "wildcardText"
- match:
    columns.1.type: "text"
- length:
    values: 1
- match:
    values.0:
    - 1
    - "bar?"
---
wildcards on text no match:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where text =~ \"fo\\\\*\" | keep id, text"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "text"
- match:
    columns.1.type: "text"
- length:
    values: 0
---
wildcards on keyword vs text:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where wildcard =~ wildcardText | keep id, wildcard, wildcardText\
          \ | sort id"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "wildcard"
- match:
    columns.1.type: "keyword"
- match:
    columns.2.name: "wildcardText"
- match:
    columns.2.type: "text"
- length:
    values: 2
- match:
    values.0:
    - 0
    - "Foo*"
    - "FOo*"
- match:
    values.1:
    - 1
    - "Bar?"
    - "bar?"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "FROM test | where NOT wildcard =~ wildcardText | keep id, wildcard,\
          \ wildcardText | sort id"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "id"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "wildcard"
- match:
    columns.1.type: "keyword"
- match:
    columns.2.name: "wildcardText"
- match:
    columns.2.type: "text"
- length:
    values: 1
- match:
    values.0:
    - 2
    - "jkl?"
    - "MNO?"
