---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    indices.create:
      index: "store"
      body:
        mappings:
          properties:
            product:
              type: "keyword"
            failed:
              type: "boolean"
    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:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    bulk:
      index: "store"
      refresh: true
      body: "{ \"index\": {} }\n{ \"product\": \"TV\", \"failed\": false }\n{ \"index\"\
        : {} }\n{ \"product\": \"TV\", \"failed\": false }\n{ \"index\": {} }\n{ \"\
        product\": \"TV\", \"failed\": false }\n{ \"index\": {} }\n{ \"product\":\
        \ \"TV\", \"failed\": false }\n{ \"index\": {} }\n{ \"product\": \"TV\", \"\
        failed\": true }\n{ \"index\": {} }\n{ \"product\": \"TV\", \"failed\": true\
        \ }\n{ \"index\": {} }\n{ \"product\": \"TV\", \"failed\": true }\n{ \"index\"\
        : {} }\n{ \"product\": \"VCR\", \"failed\": true }\n{ \"index\": {} }\n{ \"\
        product\": \"VCR\", \"failed\": true }\n{ \"index\": {} }\n{ \"product\":\
        \ \"VCR\", \"failed\": true }\n{ \"index\": {} }\n{ \"product\": \"VCR\",\
        \ \"failed\": true }\n{ \"index\": {} }\n{ \"product\": \"VCR\", \"failed\"\
        : true }\n{ \"index\": {} }\n{ \"product\": \"VCR\", \"failed\": true }\n\
        { \"index\": {} }\n{ \"product\": \"VCR\", \"failed\": true }\n{ \"index\"\
        : {} }\n{ \"product\": \"VCR\", \"failed\": true }\n{ \"index\": {} }\n{ \"\
        product\": \"VCR\", \"failed\": true }\n{ \"index\": {} }\n{ \"product\":\
        \ \"VCR\", \"failed\": true }\n{ \"index\": {} }\n{ \"product\": \"VCR\",\
        \ \"failed\": true }\n{ \"index\": {} }\n{ \"product\": \"VCR\", \"failed\"\
        : false }\n{ \"index\": {} }\n{ \"product\": \"VCR\", \"failed\": false }\n\
        { \"index\": {} }\n{ \"product\": \"VCR\", \"failed\": false }\n"
    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 p_value significant terms score:
- skip:
    features: "close_to"
- do:
    search:
      index: "store"
      body: "{\n  \"size\": 0,\n  \"query\": { \"bool\": {\"filter\":[{\"term\": {\"\
        failed\": true}}]}},\n  \"aggs\": {\n    \"significant_failures\": {\n   \
        \   \"significant_terms\": {\n        \"field\": \"product\",\n        \"\
        p_value\": {\"background_is_superset\": true}\n      }\n    }\n  }\n}\n"
    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"
- close_to:
    aggregations.significant_failures.buckets.0.score:
      value: 1.957508054106207
      error: 1.0E-6
- match:
    aggregations.significant_failures.buckets.0.key: "VCR"
- do:
    search:
      index: "store"
      body: "{\n  \"size\": 0,\n  \"query\": { \"bool\": {\"filter\":[{\"term\": {\"\
        failed\": true}}]}},\n  \"aggs\": {\n    \"significant_failures\": {\n   \
        \   \"significant_terms\": {\n        \"field\": \"product\",\n        \"\
        background_filter\": {\"bool\": {\"filter\":[{\"term\": {\"failed\": false}}]}},\n\
        \        \"p_value\": {\"background_is_superset\": false}\n      }\n    }\n\
        \  }\n}\n"
    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"
- close_to:
    aggregations.significant_failures.buckets.0.score:
      value: 1.957508054106207
      error: 1.0E-6
- match:
    aggregations.significant_failures.buckets.0.key: "VCR"
