---
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:
            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:
        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:
        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 max-sim dot product 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: "maxSimDotProduct(params.query_vector, 'vector')"
              params:
                query_vector:
                - - 1
                  - 2
                  - 1
                  - 1
                  - 1
    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: 611.316
      error: 0.01
- match:
    hits.hits.1._id: "3"
- close_to:
    hits.hits.1._score:
      value: 68.90001
      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: "maxSimDotProduct(params.query_vector, 'byte_vector')"
              params:
                query_vector:
                - - 1
                  - 2
                  - 1
                  - 1
                  - 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: 33
      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: "maxSimDotProduct(params.query_vector, 'bit_vector')"
              params:
                query_vector:
                - - 1
                  - 2
                  - 1
                  - 1
                  - 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
      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: "maxSimDotProduct(params.query_vector, 'bit_vector')"
              params:
                query_vector:
                - - 1
                  - 2
                  - 3
                  - 4
                  - 5
                  - 6
                  - 7
                  - 8
                  - 9
                  - 10
                  - 11
                  - 12
                  - 13
                  - 14
                  - 15
                  - 16
                  - 17
                  - 18
                  - 19
                  - 20
                  - 1
                  - 2
                  - 3
                  - 4
                  - 5
                  - 6
                  - 7
                  - 8
                  - 9
                  - 10
                  - 11
                  - 12
                  - 13
                  - 14
                  - 15
                  - 16
                  - 17
                  - 18
                  - 19
                  - 20
    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: 220
      error: 0.01
- match:
    hits.hits.1._id: "3"
- close_to:
    hits.hits.1._score:
      value: 147
      error: 0.01
---
Test max-sim inv hamming scoring:
- skip:
    features: "close_to"
- do:
    catch: "bad_request"
    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: "maxSimInvHamming(params.query_vector, 'vector')"
              params:
                query_vector:
                - - 1
                  - 2
                  - 1
                  - 1
                  - 1
    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:
    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: "maxSimInvHamming(params.query_vector, 'byte_vector')"
              params:
                query_vector:
                - - 1
                  - 2
                  - 1
                  - 1
                  - 1
    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: 0.675
      error: 0.01
- match:
    hits.hits.1._id: "1"
- close_to:
    hits.hits.1._score:
      value: 0.65
      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: "maxSimInvHamming(params.query_vector, 'bit_vector')"
              params:
                query_vector:
                - - 1
                  - 2
                  - 1
                  - 1
                  - 1
    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: 0.675
      error: 0.01
- match:
    hits.hits.1._id: "1"
- close_to:
    hits.hits.1._score:
      value: 0.65
      error: 0.01
