---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    test_runner_features:
    - "capabilities"
    - "contains"
    - "allowed_warnings"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "enable_lookup_join_on_aliases"
    reason: "uses LOOKUP JOIN on aliases"
- do:
    indices.create:
      index: "test"
      body:
        mappings:
          properties:
            key:
              type: "long"
            color:
              type: "keyword"
    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:
    indices.create:
      index: "test-mv"
      body:
        mappings:
          properties:
            key:
              type: "long"
            color:
              type: "keyword"
    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:
    indices.create:
      index: "test-lookup-1"
      body:
        settings:
          index:
            mode: "lookup"
        mappings:
          properties:
            key:
              type: "long"
            color:
              type: "keyword"
    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:
    indices.create:
      index: "test-lookup-2"
      body:
        settings:
          index:
            mode: "lookup"
        mappings:
          properties:
            key:
              type: "long"
            color:
              type: "keyword"
    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:
    indices.create:
      index: "test-lookup-mv"
      body:
        settings:
          index:
            mode: "lookup"
        mappings:
          properties:
            key:
              type: "long"
            color:
              type: "keyword"
    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:
    indices.create:
      index: "test-lookup-no-key"
      body:
        settings:
          index:
            mode: "lookup"
        mappings:
          properties:
            no-key:
              type: "long"
            color:
              type: "keyword"
    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:
    indices.update_aliases:
      body:
        actions:
        - add:
            index: "test-lookup-1"
            alias: "test-lookup-alias"
        - add:
            index: "test-lookup-*"
            alias: "test-lookup-alias-pattern-multiple"
        - add:
            index: "test-lookup-1*"
            alias: "test-lookup-alias-pattern-single"
    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: {}
      - key: 1
        color: "red"
      - index: {}
      - key: 2
        color: "blue"
    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-lookup-1"
      refresh: true
      body:
      - index: {}
      - key: 1
        color: "cyan"
      - index: {}
      - key: 2
        color: "yellow"
    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-mv"
      refresh: true
      body:
      - index: {}
      - key: 1
        color: "red"
      - index: {}
      - key: 2
        color: "blue"
      - index: {}
      - key:
        - 0
        - 1
        - 2
        color: null
    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-lookup-mv"
      refresh: true
      body:
      - index: {}
      - key: 1
        color: "cyan"
      - index: {}
      - key: 2
        color: "yellow"
      - index: {}
      - key:
        - 0
        - 1
        - 2
        color: "green"
    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-lookup-no-key"
      refresh: true
      body:
      - index: {}
      - no-key: 1
        color: "cyan"
      - index: {}
      - no-key: 2
        color: "yellow"
    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"
---
alias-as-lookup-index:
- skip:
    awaits_fix: "New SORT warning not in original test"
- do:
    esql.query:
      body:
        query: "FROM test | SORT key | LOOKUP JOIN test-lookup-alias ON key | LIMIT\
          \ 3"
    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"
- match:
    columns.0.name: "key"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "color"
- match:
    columns.1.type: "keyword"
- match:
    values.0:
    - 1
    - "cyan"
- match:
    values.1:
    - 2
    - "yellow"
---
alias-repeated-alias:
- skip:
    awaits_fix: "New SORT warning not in original test"
- do:
    esql.query:
      body:
        query: "FROM test-lookup-alias | SORT key | LOOKUP JOIN test-lookup-alias\
          \ ON key | LIMIT 3"
    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"
- match:
    columns.0.name: "key"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "color"
- match:
    columns.1.type: "keyword"
- match:
    values.0:
    - 1
    - "cyan"
- match:
    values.1:
    - 2
    - "yellow"
---
alias-repeated-index:
- skip:
    awaits_fix: "New SORT warning not in original test"
- do:
    esql.query:
      body:
        query: "FROM test-lookup-1 | SORT key | LOOKUP JOIN test-lookup-alias ON key\
          \ | LIMIT 3"
    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"
- match:
    columns.0.name: "key"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "color"
- match:
    columns.1.type: "keyword"
- match:
    values.0:
    - 1
    - "cyan"
- match:
    values.1:
    - 2
    - "yellow"
---
fails when alias or pattern resolves to multiple:
- skip:
    awaits_fix: "Error message changed"
- requires:
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "update_lookup_join_error_messages"
    reason: "checks updated error messages"
- do:
    esql.query:
      body:
        query: "FROM test-lookup-1 | LOOKUP JOIN test-lookup-alias-pattern-multiple\
          \ ON key"
    catch: "bad_request"
    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"
- match:
    error.type: "verification_exception"
- contains:
    error.reason: "Found 1 problem\nline 1:34: Lookup Join requires a single lookup\
      \ mode index; [test-lookup-alias-pattern-multiple] resolves to [4] indices"
---
alias-pattern-single:
- skip:
    awaits_fix: "New SORT warning not in original test"
- do:
    esql.query:
      body:
        query: "FROM test | SORT key | LOOKUP JOIN test-lookup-alias-pattern-single\
          \ ON key | LIMIT 3"
    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"
- match:
    columns.0.name: "key"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "color"
- match:
    columns.1.type: "keyword"
- match:
    values.0:
    - 1
    - "cyan"
- match:
    values.1:
    - 2
    - "yellow"
