---
setup:
- requires:
    cluster_features:
    - "rank_vectors"
    reason: "requires rank_vectors feature"
- skip:
    features:
    - "headers"
    - "headers"
    - "allowed_warnings_regex"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "test-index"
      body:
        settings:
          number_of_shards: 1
        mappings:
          properties:
            id:
              type: "keyword"
            vector:
              type: "rank_vectors"
              dims: 5
            byte_vector:
              type: "rank_vectors"
              dims: 5
              element_type: "byte"
            bit_vector:
              type: "rank_vectors"
              dims: 40
              element_type: "bit"
    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:
    index:
      index: "test-index"
      id: "1"
      body:
        id: "1"
        vector:
        - - 230.0
          - 300.33
          - -34.8988
          - 15.555
          - -200.0
        - - -0.5
          - 100.0
          - -13
          - 14.8
          - -156.0
        byte_vector:
        - - 8
          - 5
          - -15
          - 1
          - -7
        - - -1
          - 115
          - -3
          - 4
          - -128
        bit_vector:
        - - 8
          - 5
          - -15
          - 1
          - -7
        - - -1
          - 115
          - -3
          - 4
          - -128
    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:
    index:
      index: "test-index"
      id: "3"
      body:
        id: "3"
        vector:
        - - 0.5
          - 111.3
          - -13.0
          - 14.8
          - -156.0
        byte_vector:
        - - 2
          - 18
          - -5
          - 0
          - -124
        bit_vector:
        - - 2
          - 18
          - -5
          - 0
          - -124
    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.refresh: {}
    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"
---
Test vector magnitude equality:
- skip:
    features: "close_to"
- 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
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "doc['vector'].magnitudes[0]"
    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:
    hits.total: 2
- match:
    hits.hits.0._id: "1"
- close_to:
    hits.hits.0._score:
      value: 429.6021
      error: 0.01
- match:
    hits.hits.1._id: "3"
- close_to:
    hits.hits.1._score:
      value: 192.6447
      error: 0.01
- 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
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "doc['byte_vector'].magnitudes[0]"
    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:
    hits.total: 2
- match:
    hits.hits.0._id: "3"
- close_to:
    hits.hits.0._score:
      value: 125.41531
      error: 0.01
- match:
    hits.hits.1._id: "1"
- close_to:
    hits.hits.1._score:
      value: 19.07878
      error: 0.01
- 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
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "doc['bit_vector'].magnitudes[0]"
    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:
    hits.total: 2
- match:
    hits.hits.0._id: "1"
- close_to:
    hits.hits.0._score:
      value: 3.872983
      error: 0.01
- match:
    hits.hits.1._id: "3"
- close_to:
    hits.hits.1._score:
      value: 3.464101
      error: 0.01
---
Test vector value scoring:
- skip:
    features: "close_to"
- 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
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "doc['vector'].vectorValues.next()[0];"
    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:
    hits.total: 2
- match:
    hits.hits.0._id: "1"
- close_to:
    hits.hits.0._score:
      value: 230
      error: 0.01
- match:
    hits.hits.1._id: "3"
- close_to:
    hits.hits.1._score:
      value: 0.5
      error: 0.01
- 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
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "doc['byte_vector'].vectorValues.next()[0];"
    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:
    hits.total: 2
- match:
    hits.hits.0._id: "1"
- close_to:
    hits.hits.0._score:
      value: 8
      error: 0.01
- match:
    hits.hits.1._id: "3"
- close_to:
    hits.hits.1._score:
      value: 2
      error: 0.01
- 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
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "doc['bit_vector'].vectorValues.next()[0];"
    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:
    hits.total: 2
- match:
    hits.hits.0._id: "1"
- close_to:
    hits.hits.0._score:
      value: 8
      error: 0.01
- match:
    hits.hits.1._id: "3"
- close_to:
    hits.hits.1._score:
      value: 2
      error: 0.01
---
Test doc value vector access:
- skip:
    features: "close_to"
- do:
    search:
      _source: false
      index: "test-index"
      body:
        docvalue_fields:
        - "name"
        - "bit_vector"
        - "byte_vector"
        - "vector"
        sort:
        - id: "asc"
    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:
    hits.hits.0._id: "1"
- close_to:
    hits.hits.0.fields.vector.0.0.0:
      value: 230
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.0.1:
      value: 300.33
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.0.2:
      value: -34.8988
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.0.3:
      value: 15.555
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.0.4:
      value: -200
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.1.0:
      value: -0.5
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.1.1:
      value: 100
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.1.2:
      value: -13
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.1.3:
      value: 14.8
      error: 1.0E-4
- close_to:
    hits.hits.0.fields.vector.0.1.4:
      value: -156
      error: 1.0E-4
- match:
    hits.hits.0.fields.byte_vector.0.0:
    - 8
    - 5
    - -15
    - 1
    - -7
- match:
    hits.hits.0.fields.bit_vector.0.0:
    - 8
    - 5
    - -15
    - 1
    - -7
- match:
    hits.hits.0.fields.byte_vector.0.1:
    - -1
    - 115
    - -3
    - 4
    - -128
- match:
    hits.hits.0.fields.bit_vector.0.1:
    - -1
    - 115
    - -3
    - 4
    - -128
