---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "gte_v7.7.0"
    reason: "implemented in 7.7.0"
- do:
    indices.create:
      index: "test"
      body:
        mappings:
          properties:
            text:
              type: "text"
              analyzer: "standard"
              fields:
                raw:
                  type: "keyword"
            nested1:
              type: "nested"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    bulk:
      refresh: true
      body:
      - "{\"index\": {\"_index\": \"test\", \"_id\": \"1\"}}"
      - "{\"text\" : \"Some like it hot, some like it cold\", \"nested1\": [{\"foo\"\
        : \"bar1\"}]}"
      - "{\"index\": {\"_index\": \"test\", \"_id\": \"2\"}}"
      - "{\"text\" : \"Its cold outside, theres no kind of atmosphere\", \"nested1\"\
        : [{\"foo\": \"bar2\"}]}"
      - "{\"index\": {\"_index\": \"test\", \"_id\": \"3\"}}"
      - "{\"text\" : \"Baby its cold there outside\", \"nested1\": [{\"foo\": \"bar3\"\
        }]}"
      - "{\"index\": {\"_index\": \"test\", \"_id\": \"4\"}}"
      - "{\"text\" : \"Outside it is cold and wet\", \"nested1\": [{\"foo\": \"bar4\"\
        }]}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
teardown:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "gte_v7.7.0"
    reason: "implemented in 7.7.0"
- do:
    cluster.put_settings:
      body:
        persistent:
          search.allow_expensive_queries: null
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
Test disallow expensive queries:
- requires:
    cluster_features:
    - "gte_v7.7.0"
    reason: "implemented in 7.7.0"
- do:
    cluster.get_settings:
      flat_settings: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- is_false: "search.allow_expensive_queries"
- do:
    cluster.put_settings:
      body:
        persistent:
          search.allow_expensive_queries: "false"
      flat_settings: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    persistent:
      search.allow_expensive_queries: "false"
- do:
    catch: "/\\[prefix\\] queries cannot be executed when \\'search.allow_expensive_queries\\\
      ' is set to false. For optimised prefix queries on text fields please enable\
      \ \\[index_prefixes\\]./"
    search:
      index: "test"
      body:
        query:
          prefix:
            text:
              value: "out"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    catch: "/\\[fuzzy\\] queries cannot be executed when \\'search.allow_expensive_queries\\\
      ' is set to false./"
    search:
      index: "test"
      body:
        query:
          fuzzy:
            text:
              value: "outwide"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    catch: "/\\[regexp\\] queries cannot be executed when \\'search.allow_expensive_queries\\\
      ' is set to false./"
    search:
      index: "test"
      body:
        query:
          regexp:
            text:
              value: ".*ou.*id.*"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    catch: "/\\[wildcard\\] queries cannot be executed when \\'search.allow_expensive_queries\\\
      ' is set to false./"
    search:
      index: "test"
      body:
        query:
          wildcard:
            text:
              value: "out?ide"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    catch: "/\\[range\\] queries on \\[text\\] or \\[keyword\\] fields cannot be executed\
      \ when \\'search.allow_expensive_queries\\' is set to false./"
    search:
      index: "test"
      body:
        query:
          range:
            text:
              gte: "theres"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    catch: "/\\[range\\] queries on \\[text\\] or \\[keyword\\] fields cannot be executed\
      \ when \\'search.allow_expensive_queries\\' is set to false./"
    search:
      index: "test"
      body:
        query:
          range:
            text.raw:
              gte: "Outside it is cold and wet"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    catch: "/\\[joining\\] queries cannot be executed when \\'search.allow_expensive_queries\\\
      ' is set to false./"
    search:
      index: "test"
      body:
        query:
          nested:
            path: "nested1"
            query:
              bool:
                must:
                - match:
                    nested1.foo: "bar2"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
