---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    test_runner_features: "headers"
    cluster_features:
    - "gte_v7.10.1"
    reason: "version field is added to 7.10"
- do:
    indices.create:
      index: "test_index"
      body:
        mappings:
          properties:
            version:
              type: "version"
    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:
    bulk:
      refresh: true
      body:
      - "{ \"index\" : { \"_index\" : \"test_index\", \"_id\" : \"1\" } }"
      - "{\"version\": \"1.1.0\" }"
      - "{ \"index\" : { \"_index\" : \"test_index\", \"_id\" : \"2\" } }"
      - "{\"version\": \"2.0.0-beta\" }"
      - "{ \"index\" : { \"_index\" : \"test_index\", \"_id\" : \"3\" } }"
      - "{\"version\": \"3.1.0\" }"
    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"
---
Store malformed:
- do:
    indices.create:
      index: "test_malformed"
      body:
        mappings:
          properties:
            version:
              type: "version"
    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:
    bulk:
      refresh: true
      body:
      - "{ \"index\" : { \"_index\" : \"test_malformed\", \"_id\" : \"1\" } }"
      - "{\"version\": \"1.1.0\" }"
      - "{ \"index\" : { \"_index\" : \"test_malformed\", \"_id\" : \"2\" } }"
      - "{\"version\": \"2.0.0-beta\" }"
      - "{ \"index\" : { \"_index\" : \"test_malformed\", \"_id\" : \"3\" } }"
      - "{\"version\": \"v3.1.0\" }"
      - "{ \"index\" : { \"_index\" : \"test_malformed\", \"_id\" : \"4\" } }"
      - "{\"version\": \"1.el6\" }"
    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:
    search:
      index: "test_malformed"
      body:
        query:
          match:
            version: "1.el6"
    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:
    search:
      index: "test_malformed"
      body:
        query:
          match_all: {}
        sort:
          version: "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.total.value: 4
- match:
    hits.hits.0._source.version: "1.1.0"
- match:
    hits.hits.1._source.version: "2.0.0-beta"
- match:
    hits.hits.2._source.version: "1.el6"
- match:
    hits.hits.3._source.version: "v3.1.0"
---
Basic ranges:
- do:
    search:
      index: "test_index"
      body:
        query:
          range:
            version:
              gt: "1.1.0"
              lt: "9999"
    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.total.value: 2
- do:
    search:
      index: "test_index"
      body:
        query:
          range:
            version:
              gte: "1.1.0"
              lt: "9999"
    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.total.value: 3
- do:
    search:
      index: "test_index"
      body:
        query:
          range:
            version:
              gte: "2.0.0"
              lt: "9999"
    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.total.value: 1
- do:
    search:
      index: "test_index"
      body:
        query:
          range:
            version:
              gte: "2.0.0-alpha"
              lt: "9999"
    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.total.value: 2
