---
"Non positive null_value":

  - requires:
      cluster_features: ["gte_v8.9.0"]
      reason: "null_value parameter was added in 8.9.0"

  - do:
      catch: /\[null_value\] must be a positive normal float for field of type \[rank_feature\]/
      indices.create:
        index: test2
        body:
          settings:
            number_of_replicas: 0
          mappings:
            properties:
              pagerank:
                type: rank_feature
                null_value: -3

---
"Search rank_feature with and without null_value":

  - requires:
      cluster_features: ["gte_v8.9.0"]
      reason: "null_value parameter was added in 8.9.0"

  - do:
      indices.create:
        index: test1
        body:
          settings:
            number_of_replicas: 0
          mappings:
            properties:
              pagerank:
                type: rank_feature
                null_value: 100
              url_length:
                type: rank_feature

  - do:
      index:
        index: test1
        id: "1"
        body:
          pagerank: 10
          url_length: 50

  - do:
      index:
        index: test1
        id: "2"
        body:
          pagerank: null
          url_length: null

  # can't index a field value equal to an empty string
  - do:
      catch: /failed to parse field \[pagerank\] of type \[rank_feature\] in document/
      index:
        index: test1
        id: "wrong_document1"
        body:
          pagerank: ""

  - do:
      indices.refresh: {}

  # docs with null values are absent in search results
  - do:
      search:
        index: test1
        body:
          query:
            rank_feature:
              field: url_length

  - match:
      hits.total.value: 1

  - match:
      hits.hits.0._id: "1"

  # docs with null values are present in search results
  - do:
      search:
        index: test1
        body:
          query:
            rank_feature:
              field: pagerank
          fields:
            - field: 'pagerank'
            - field: 'url_length'

  - match:
      hits.total.value: 2

  - match:
      hits.hits.0._id: "2"

  - match:
      hits.hits.1._id: "1"

  - match: { hits.hits.0._source.pagerank: null }
  - match: { hits.hits.0.fields.pagerank.0: 100 }
  - match: { hits.hits.0._source.url_length: null }
  - is_false: hits.hits.0.fields.url_length
