---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features: "gte_v8.5.0"
    reason: "filtered alias for kNN search added in 8.5"
- do:
    indices.create:
      index: "test"
      body:
        settings:
          number_of_shards: 1
        mappings:
          dynamic: false
          properties:
            test_vector:
              type: "dense_vector"
              dims: 4
              index: true
              similarity: "l2_norm"
              index_options:
                type: "hnsw"
                m: 16
                ef_construction: 200
            name:
              type: "keyword"
              store: true
        aliases:
          test-alias:
            filter:
              term:
                name: "v1"
    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:
    index:
      index: "test"
      id: "1"
      body:
        name: "v1"
        test_vector:
        - 230.0
        - 300.33
        - -34.8988
        - 15.555
    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:
    index:
      index: "test"
      id: "2"
      body:
        name: "v1"
        test_vector:
        - 0.5
        - 0.5
        - 0.5
        - -1
    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:
    index:
      index: "test"
      id: "3"
      body:
        name: "v2"
        test_vector:
        - 0.5
        - 0.5
        - 0.5
        - 0.5
    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:
    index:
      index: "test"
      id: "4"
      body:
        name: "v2"
        test_vector:
        - 0.5
        - 0.5
        - 0.5
        - 0
    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:
    index:
      index: "test"
      id: "5"
      body:
        name: "v2"
        test_vector:
        - 0.5
        - 0.5
        - 0.5
        - 0.4
    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:
    indices.refresh: {}
    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"
---
kNN filter alias:
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - -1.0
          k: 2
          num_candidates: 100
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "v1"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - -1.0
          k: 2
          num_candidates: 100
          filter:
            term:
              name: "v1"
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "v1"
- do:
    search:
      index: "test-alias"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - -1.0
          k: 2
          num_candidates: 100
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "v1"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - 0.5
          k: 2
          num_candidates: 100
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "3"
- match:
    hits.hits.1.fields.name.0: "v2"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - 0.5
          k: 2
          num_candidates: 100
          filter:
            term:
              name: "v1"
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "v1"
- do:
    search:
      index: "test-alias"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - 0.5
          k: 2
          num_candidates: 100
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "v1"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - 0.5
          k: 3
          num_candidates: 100
    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:
    hits.total.value: 3
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "3"
- match:
    hits.hits.1.fields.name.0: "v2"
- match:
    hits.hits.2._id: "5"
- match:
    hits.hits.2.fields.name.0: "v2"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - 0.5
          k: 3
          num_candidates: 100
          filter:
            term:
              name: "v1"
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "v1"
- do:
    search:
      index: "test-alias"
      body:
        fields:
        - "name"
        knn:
          field: "test_vector"
          query_vector:
          - 230.0
          - 300.33
          - -34.8988
          - 0.5
          k: 3
          num_candidates: 100
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "v1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "v1"
