---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "test_1"
      body:
        settings:
          index.analyze.max_token_count: 3
    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"
---
_analyze with No. generated tokens less than or equal to index.analyze.max_token_count should succeed:
- do:
    indices.analyze:
      index: "test_1"
      body:
        text: "This should succeed"
        analyzer: "standard"
    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"
- length:
    tokens: 3
- match:
    tokens.0.token: "this"
- match:
    tokens.1.token: "should"
- match:
    tokens.2.token: "succeed"
---
_analyze with No. generated tokens more than index.analyze.max_token_count should fail:
- do:
    catch: "/The number of tokens produced by calling _analyze has exceeded the allowed\
      \ maximum of \\[3\\]. This limit can be set by changing the \\[index.analyze.max_token_count\\\
      ] index level setting\\./"
    indices.analyze:
      index: "test_1"
      body:
        text: "This should fail as it exceeds limit"
        analyzer: "standard"
    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"
---
_analyze with explain with No. generated tokens more than index.analyze.max_token_count should fail:
- do:
    catch: "/The number of tokens produced by calling _analyze has exceeded the allowed\
      \ maximum of \\[3\\]. This limit can be set by changing the \\[index.analyze.max_token_count\\\
      ] index level setting\\./"
    indices.analyze:
      index: "test_1"
      body:
        text: "This should fail as it exceeds limit"
        analyzer: "standard"
        explain: 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"
