---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features: "gte_v8.0.0"
    reason: "kNN search added in 8.0"
- do:
    indices.create:
      index: "test"
      body:
        mappings:
          properties:
            name:
              type: "keyword"
            vector:
              type: "dense_vector"
              dims: 5
              index: true
              similarity: "l2_norm"
              index_options:
                type: "hnsw"
                m: 16
                ef_construction: 200
            another_vector:
              type: "dense_vector"
              dims: 5
              index: true
              similarity: "l2_norm"
              index_options:
                type: "hnsw"
                m: 16
                ef_construction: 200
    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: "cow.jpg"
        vector:
        - 230.0
        - 300.33
        - -34.8988
        - 15.555
        - -200.0
        another_vector:
        - 130.0
        - 115.0
        - -1.02
        - 15.555
        - -100.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: "2"
      body:
        name: "moose.jpg"
        vector:
        - -0.5
        - 100.0
        - -13
        - 14.8
        - -156.0
        another_vector:
        - -0.5
        - 50.0
        - -1
        - 1
        - 120
    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: "rabbit.jpg"
        vector:
        - 0.5
        - 111.3
        - -13.0
        - 14.8
        - -156.0
        another_vector:
        - -0.5
        - 11.0
        - 0
        - 12
        - 111.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:
    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 search only:
- requires:
    cluster_features: "gte_v8.4.0"
    reason: "kNN added to search endpoint in 8.4"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 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"
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.fields.name.0: "moose.jpg"
- match:
    hits.hits.1._id: "3"
- match:
    hits.hits.1.fields.name.0: "rabbit.jpg"
---
kNN multi-field search only:
- requires:
    cluster_features: "gte_v8.7.0"
    reason: "multi-field kNN search added to search endpoint in 8.7"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
        - field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 3
        - field: "another_vector"
          query_vector:
          - -0.5
          - 11.0
          - 0
          - 12
          - 111.0
          k: 2
          num_candidates: 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"
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.fields.name.0: "rabbit.jpg"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "moose.jpg"
---
kNN search plus query:
- requires:
    cluster_features: "gte_v8.4.0"
    reason: "kNN added to search endpoint in 8.4"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 3
        query:
          term:
            name: "cow.jpg"
    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.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "cow.jpg"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "moose.jpg"
- match:
    hits.hits.2._id: "3"
- match:
    hits.hits.2.fields.name.0: "rabbit.jpg"
---
kNN multi-field search with query:
- requires:
    cluster_features: "gte_v8.7.0"
    reason: "multi-field kNN search added to search endpoint in 8.7"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
        - field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 3
        - field: "another_vector"
          query_vector:
          - -0.5
          - 11.0
          - 0
          - 12
          - 111.0
          k: 2
          num_candidates: 3
        query:
          term:
            name: "cow.jpg"
    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.hits.0._id: "3"
- match:
    hits.hits.0.fields.name.0: "rabbit.jpg"
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.1.fields.name.0: "cow.jpg"
- match:
    hits.hits.2._id: "2"
- match:
    hits.hits.2.fields.name.0: "moose.jpg"
---
kNN search with filter:
- requires:
    cluster_features: "gte_v8.4.0"
    reason: "kNN added to search endpoint in 8.4"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 3
          filter:
            term:
              name: "rabbit.jpg"
    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: 1
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.fields.name.0: "rabbit.jpg"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 3
          filter:
          - term:
              name: "rabbit.jpg"
          - term:
              _id: 2
    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: 0
---
kNN search with explicit search_type:
- requires:
    cluster_features: "gte_v8.4.0"
    reason: "kNN added to search endpoint in 8.4"
- do:
    catch: "bad_request"
    search:
      index: "test"
      search_type: "query_then_fetch"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 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"
- match:
    error.root_cause.0.type: "illegal_argument_exception"
- match:
    error.root_cause.0.reason: "cannot set [search_type] when using [knn] search,\
      \ since the search type is determined automatically"
---
kNN search in _knn_search endpoint:
- skip:
    features:
    - "allowed_warnings"
- do:
    allowed_warnings:
    - "The kNN search API has been replaced by the `knn` option in the search API."
    knn_search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 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"
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.fields.name.0: "moose.jpg"
- match:
    hits.hits.1._id: "3"
- match:
    hits.hits.1.fields.name.0: "rabbit.jpg"
---
kNN search with filter in _knn_search endpoint:
- requires:
    cluster_features: "gte_v8.2.0"
    reason: "kNN with filtering added in 8.2"
    test_runner_features:
    - "allowed_warnings"
- do:
    allowed_warnings:
    - "The kNN search API has been replaced by the `knn` option in the search API."
    knn_search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 3
        filter:
          term:
            name: "rabbit.jpg"
    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: 1
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.fields.name.0: "rabbit.jpg"
- do:
    allowed_warnings:
    - "The kNN search API has been replaced by the `knn` option in the search API."
    knn_search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 3
        filter:
        - term:
            name: "rabbit.jpg"
        - term:
            _id: 2
    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: 0
---
Test nonexistent field is match none:
- requires:
    cluster_features: "gte_v8.16.0"
    reason: "non-existent field handling improved in 8.16"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "nonexistent"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 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"
- length:
    hits.hits: 0
- do:
    indices.create:
      index: "test_nonexistent"
      body:
        mappings:
          properties:
            name:
              type: "keyword"
            vector:
              type: "dense_vector"
              element_type: "float"
              dims: 5
              index: true
              similarity: "l2_norm"
        settings:
          index.query.parse.allow_unmapped_fields: false
    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: "bad_request"
    search:
      index: "test_nonexistent"
      body:
        fields:
        - "name"
        knn:
          field: "nonexistent"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 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"
- match:
    error.root_cause.0.type: "query_shard_exception"
- match:
    error.root_cause.0.reason: "No field mapping can be found for the field with name\
      \ [nonexistent]"
---
KNN Vector similarity search only:
- requires:
    cluster_features: "gte_v8.8.0"
    reason: "kNN similarity added in 8.8"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          similarity: 11
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.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"
- length:
    hits.hits: 1
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.fields.name.0: "moose.jpg"
---
Vector similarity with filter only:
- requires:
    cluster_features: "gte_v8.8.0"
    reason: "kNN similarity added in 8.8"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          similarity: 11
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          filter:
            term:
              name: "moose.jpg"
    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:
    hits.hits: 1
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.fields.name.0: "moose.jpg"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          similarity: 110
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          filter:
            term:
              name: "cow.jpg"
    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:
    hits.hits: 0
---
Knn search with mip:
- requires:
    cluster_features: "gte_v8.11.0"
    reason: "mip similarity added in 8.11"
    test_runner_features: "close_to"
- do:
    indices.create:
      index: "mip"
      body:
        mappings:
          properties:
            name:
              type: "keyword"
            vector:
              type: "dense_vector"
              dims: 5
              index: true
              similarity: "max_inner_product"
              index_options:
                type: "hnsw"
                m: 16
                ef_construction: 200
    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: "mip"
      id: "1"
      body:
        name: "cow.jpg"
        vector:
        - 230.0
        - 300.33
        - -34.8988
        - 15.555
        - -200.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: "mip"
      id: "2"
      body:
        name: "moose.jpg"
        vector:
        - -0.5
        - 100.0
        - -13
        - 14.8
        - -156.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: "mip"
      id: "3"
      body:
        name: "rabbit.jpg"
        vector:
        - 0.5
        - 111.3
        - -13.0
        - 14.8
        - -156.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:
    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"
- do:
    search:
      index: "mip"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.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"
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "1"
- close_to:
    hits.hits.0._score:
      value: 58694.902
      error: 0.01
- match:
    hits.hits.1._id: "3"
- close_to:
    hits.hits.1._score:
      value: 34702.79
      error: 0.01
- match:
    hits.hits.2._id: "2"
- close_to:
    hits.hits.2._score:
      value: 33686.29
      error: 0.01
- do:
    search:
      index: "mip"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          filter:
            term:
              name: "moose.jpg"
    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:
    hits.hits: 1
- match:
    hits.hits.0._id: "2"
- close_to:
    hits.hits.0._score:
      value: 33686.29
      error: 0.01
---
Knn search with _name:
- requires:
    cluster_features: "gte_v8.15.0"
    reason: "support for _name in knn was added in 8.15"
    test_runner_features: "close_to"
- do:
    search:
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 3
          num_candidates: 3
          _name: "my_knn_query"
        query:
          term:
            name:
              term: "cow.jpg"
              _name: "my_query"
    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.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "cow.jpg"
- match:
    hits.hits.0.matched_queries.0: "my_knn_query"
- match:
    hits.hits.0.matched_queries.1: "my_query"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "moose.jpg"
- match:
    hits.hits.1.matched_queries.0: "my_knn_query"
- match:
    hits.hits.2._id: "3"
- match:
    hits.hits.2.fields.name.0: "rabbit.jpg"
- match:
    hits.hits.2.matched_queries.0: "my_knn_query"
---
kNN search on empty index should return 0 results and not an error:
- requires:
    cluster_features: "gte_v8.15.1"
    reason: "Error fixed in 8.15.1"
- do:
    indices.create:
      index: "test_empty"
      body:
        mappings:
          properties:
            vector:
              type: "dense_vector"
    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:
    search:
      index: "test_empty"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 2
          num_candidates: 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"
- match:
    hits.total.value: 0
---
Vector rescoring has no effect for non-quantized vectors and provides same results as non-rescored knn:
- requires:
    reason: "Quantized vector rescoring is required"
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "GET"
      path: "/_search"
      capabilities:
      - "knn_quantized_vector_rescore_oversample"
- skip:
    features: "headers"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 3
          num_candidates: 3
    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: 3
- set:
    hits.hits.0._score: "knn_score0"
- set:
    hits.hits.1._score: "knn_score1"
- set:
    hits.hits.2._score: "knn_score2"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      index: "test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 3
          num_candidates: 3
          rescore_vector:
            oversample: 1.5
    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: 3
- match:
    hits.hits.0._score: "$knn_score0"
- match:
    hits.hits.1._score: "$knn_score1"
- match:
    hits.hits.2._score: "$knn_score2"
---
Updating dim to null is not allowed:
- requires:
    cluster_features: "mapper.npe_on_dims_update_fix"
    reason: "dims update fix"
- do:
    indices.create:
      index: "test_index"
    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.put_mapping:
      index: "test_index"
      body:
        properties:
          embedding:
            type: "dense_vector"
            dims: 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:
    catch: "bad_request"
    indices.put_mapping:
      index: "test_index"
      body:
        properties:
          embedding:
            type: "dense_vector"
    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"
---
Searching with no data dimensions specified:
- requires:
    cluster_features: "search.vectors.no_dimensions_bugfix"
    reason: "Search with no dimensions bugfix"
- do:
    indices.create:
      index: "empty-test"
      body:
        mappings:
          properties:
            vector:
              type: "dense_vector"
              index: 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"
- do:
    search:
      index: "empty-test"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          - -156.0
          k: 3
          num_candidates: 3
          rescore_vector:
            oversample: 1.5
          similarity: 0.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"
- match:
    hits.total.value: 0
