<commit_before>setup:
  - do:
      indices.create:
        index: test_1
        body:
          settings:
            number_of_replicas: 0
          mappings:
            properties:
              str:
                type: keyword
              number:
                type: integer

  - do:
      bulk:
        index: test_1
        refresh: true
        body:
          - '{"index": {}}'
          - '{"_doc_count": 10, "str": "abc", "number" : 500, "unmapped": "abc" }'
          - '{"index": {}}'
          - '{"_doc_count": 5, "str": "xyz", "number" : 100, "unmapped": "xyz" }'
          - '{"index": {}}'
          - '{"_doc_count": 7, "str": "foo", "number" : 100, "unmapped": "foo" }'
          - '{"index": {}}'
          - '{"_doc_count": 1, "str": "foo", "number" : 200, "unmapped": "foo" }'
          - '{"index": {}}'
          - '{"str": "abc", "number" : 500, "unmapped": "abc" }'

---
"Test numeric terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" : { "num_terms" : { "terms" : { "field" : "number" } } } }

  - match: { hits.total: 5 }
  - length: { aggregations.num_terms.buckets: 3 }
  - match: { aggregations.num_terms.buckets.0.key: 100 }
  - match: { aggregations.num_terms.buckets.0.doc_count: 12 }
  - match: { aggregations.num_terms.buckets.1.key: 500 }
  - match: { aggregations.num_terms.buckets.1.doc_count: 11 }
  - match: { aggregations.num_terms.buckets.2.key: 200 }
  - match: { aggregations.num_terms.buckets.2.doc_count: 1 }


---
"Test keyword terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str" } } } }

  - match: { hits.total: 5 }
  - length: { aggregations.str_terms.buckets: 3 }
  - match: { aggregations.str_terms.buckets.0.key: "abc" }
  - match: { aggregations.str_terms.buckets.0.doc_count: 11 }
  - match: { aggregations.str_terms.buckets.1.key: "foo" }
  - match: { aggregations.str_terms.buckets.1.doc_count: 8 }
  - match: { aggregations.str_terms.buckets.2.key: "xyz" }
  - match: { aggregations.str_terms.buckets.2.doc_count: 5 }

---

"Test unmapped string terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      bulk:
        index: test_2
        refresh: true
        body:
          - '{"index": {}}'
          - '{"_doc_count": 10, "str": "abc" }'
          - '{"index": {}}'
          - '{"str": "abc" }'
  - do:
      search:
        index: test_2
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str.keyword" } } } }

  - match: { hits.total: 2 }
  - length: { aggregations.str_terms.buckets: 1 }
  - match: { aggregations.str_terms.buckets.0.key: "abc" }
  - match: { aggregations.str_terms.buckets.0.doc_count: 11 }

---
"Test composite str_terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" :
          { "composite_agg" : { "composite" :
               {
                 "sources": ["str_terms": { "terms": { "field": "str" } }]
               }
           }
         }
      }

  - match: { hits.total: 5 }
  - length: { aggregations.composite_agg.buckets: 3 }
  - match: { aggregations.composite_agg.buckets.0.key.str_terms: "abc" }
  - match: { aggregations.composite_agg.buckets.0.doc_count: 11 }
  - match: { aggregations.composite_agg.buckets.1.key.str_terms: "foo" }
  - match: { aggregations.composite_agg.buckets.1.doc_count: 8 }
  - match: { aggregations.composite_agg.buckets.2.key.str_terms: "xyz" }
  - match: { aggregations.composite_agg.buckets.2.doc_count: 5 }


---
"Test composite num_terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" :
          { "composite_agg" :
              { "composite" :
                {
                  "sources": ["num_terms" : { "terms" : { "field" : "number" } }]
                }
            }
          }
        }

  - match: { hits.total: 5 }
  - length: { aggregations.composite_agg.buckets: 3 }
  - match: { aggregations.composite_agg.buckets.0.key.num_terms: 100 }
  - match: { aggregations.composite_agg.buckets.0.doc_count: 12 }
  - match: { aggregations.composite_agg.buckets.1.key.num_terms: 200 }
  - match: { aggregations.composite_agg.buckets.1.doc_count: 1 }
  - match: { aggregations.composite_agg.buckets.2.key.num_terms: 500 }
  - match: { aggregations.composite_agg.buckets.2.doc_count: 11 }

---
"Test filters agg with doc_count":
  - skip:
      version: " - 7.99.99"
      reason: "fixed in 8.0.0 to be backported to 7.11.2"
  - do:
      search:
        body:
          profile: true
          size: 0
          aggs:
            f:
              filters:
                filters:
                  abc:
                    match:
                      str: abc
                  foo:
                    match:
                      str: foo<commit_msg>Update skip after backport of #68930  (#69233)<commit_after>setup:
  - do:
      indices.create:
        index: test_1
        body:
          settings:
            number_of_replicas: 0
          mappings:
            properties:
              str:
                type: keyword
              number:
                type: integer

  - do:
      bulk:
        index: test_1
        refresh: true
        body:
          - '{"index": {}}'
          - '{"_doc_count": 10, "str": "abc", "number" : 500, "unmapped": "abc" }'
          - '{"index": {}}'
          - '{"_doc_count": 5, "str": "xyz", "number" : 100, "unmapped": "xyz" }'
          - '{"index": {}}'
          - '{"_doc_count": 7, "str": "foo", "number" : 100, "unmapped": "foo" }'
          - '{"index": {}}'
          - '{"_doc_count": 1, "str": "foo", "number" : 200, "unmapped": "foo" }'
          - '{"index": {}}'
          - '{"str": "abc", "number" : 500, "unmapped": "abc" }'

---
"Test numeric terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" : { "num_terms" : { "terms" : { "field" : "number" } } } }

  - match: { hits.total: 5 }
  - length: { aggregations.num_terms.buckets: 3 }
  - match: { aggregations.num_terms.buckets.0.key: 100 }
  - match: { aggregations.num_terms.buckets.0.doc_count: 12 }
  - match: { aggregations.num_terms.buckets.1.key: 500 }
  - match: { aggregations.num_terms.buckets.1.doc_count: 11 }
  - match: { aggregations.num_terms.buckets.2.key: 200 }
  - match: { aggregations.num_terms.buckets.2.doc_count: 1 }


---
"Test keyword terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str" } } } }

  - match: { hits.total: 5 }
  - length: { aggregations.str_terms.buckets: 3 }
  - match: { aggregations.str_terms.buckets.0.key: "abc" }
  - match: { aggregations.str_terms.buckets.0.doc_count: 11 }
  - match: { aggregations.str_terms.buckets.1.key: "foo" }
  - match: { aggregations.str_terms.buckets.1.doc_count: 8 }
  - match: { aggregations.str_terms.buckets.2.key: "xyz" }
  - match: { aggregations.str_terms.buckets.2.doc_count: 5 }

---

"Test unmapped string terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      bulk:
        index: test_2
        refresh: true
        body:
          - '{"index": {}}'
          - '{"_doc_count": 10, "str": "abc" }'
          - '{"index": {}}'
          - '{"str": "abc" }'
  - do:
      search:
        index: test_2
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str.keyword" } } } }

  - match: { hits.total: 2 }
  - length: { aggregations.str_terms.buckets: 1 }
  - match: { aggregations.str_terms.buckets.0.key: "abc" }
  - match: { aggregations.str_terms.buckets.0.doc_count: 11 }

---
"Test composite str_terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" :
          { "composite_agg" : { "composite" :
               {
                 "sources": ["str_terms": { "terms": { "field": "str" } }]
               }
           }
         }
      }

  - match: { hits.total: 5 }
  - length: { aggregations.composite_agg.buckets: 3 }
  - match: { aggregations.composite_agg.buckets.0.key.str_terms: "abc" }
  - match: { aggregations.composite_agg.buckets.0.doc_count: 11 }
  - match: { aggregations.composite_agg.buckets.1.key.str_terms: "foo" }
  - match: { aggregations.composite_agg.buckets.1.doc_count: 8 }
  - match: { aggregations.composite_agg.buckets.2.key.str_terms: "xyz" }
  - match: { aggregations.composite_agg.buckets.2.doc_count: 5 }


---
"Test composite num_terms agg with doc_count":
  - skip:
      version: " - 7.10.99"
      reason: "doc_count field has been added in 7.11"
  - do:
      search:
        rest_total_hits_as_int: true
        body: { "size" : 0, "aggs" :
          { "composite_agg" :
              { "composite" :
                {
                  "sources": ["num_terms" : { "terms" : { "field" : "number" } }]
                }
            }
          }
        }

  - match: { hits.total: 5 }
  - length: { aggregations.composite_agg.buckets: 3 }
  - match: { aggregations.composite_agg.buckets.0.key.num_terms: 100 }
  - match: { aggregations.composite_agg.buckets.0.doc_count: 12 }
  - match: { aggregations.composite_agg.buckets.1.key.num_terms: 200 }
  - match: { aggregations.composite_agg.buckets.1.doc_count: 1 }
  - match: { aggregations.composite_agg.buckets.2.key.num_terms: 500 }
  - match: { aggregations.composite_agg.buckets.2.doc_count: 11 }

---
"Test filters agg with doc_count":
  - skip:
      version: " - 7.11.1"
      reason: "fixed in 7.11.2"
  - do:
      search:
        body:
          profile: true
          size: 0
          aggs:
            f:
              filters:
                filters:
                  abc:
                    match:
                      str: abc
                  foo:
                    match:
                      str: foo
{'fraction_non_alphanumeric': 0.16048475945648183, 'fraction_numerical': 0.0297466030113845, 'mean_word_length': 1.8809838667019307, 'pattern_counts': {'":': 70, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4159146', 'n_tokens_mistral': 4310, 'n_tokens_neox': 3886, 'n_words': 760}