# Use custom field instead of doc\_count

**URL:** <https://discuss.elastic.co/t/use-custom-field-instead-of-doc-count/245234>\
**Category:** Elasticsearch\
**Created:** [August 17, 2020, 12:34pm UTC](https://discuss.elastic.co/t/use-custom-field-instead-of-doc-count/245234 "2020-08-17T12:34:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sesha](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@sesha](https://discuss.elastic.co/u/sesha)\
**Post date:** [August 17, 2020, 12:34pm UTC](https://discuss.elastic.co/t/use-custom-field-instead-of-doc-count/245234/1 "2020-08-17T12:34:14Z")

</div>

Need to use custom field instead of doc\_count  
Is it possible to change the default configuration to change doc\_count to sum by custom field

**Query:**

```auto
    GET test/_search
    {
    "aggs": {
      "NAME": {
        "terms": {
          "field": "Name.keyword",
          "size": 10
        }
      }
    }  
    }

```

**Output**

```auto
    {
      "took" : 3,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 3,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "80xe_HMBH8nw72Wo3YDA",
            "_score" : 1.0,
            "_source" : {
              "Name" : "Book",
              "count" : 20
            }
          },
          {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "-kxf_HMBH8nw72WoAoBo",
            "_score" : 1.0,
            "_source" : {
              "Name" : "Book2",
              "count" : 10
            }
          },
          {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "B0xf_HMBH8nw72WoQYGN",
            "_score" : 1.0,
            "_source" : {
              "Name" : "Book2",
              "count" : 5
            }
          }
        ]
      },
      "aggregations" : {
        "NAME" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [
            {
              "key" : "Book2",
              "doc_count" : 2
            },
            {
              "key" : "Book",
              "doc_count" : 1
            }
          ]
        }
      }
    }

```

**Expected:**

```auto
    {
    "aggregations" : {
        "NAME" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [
            {
              "key" : "Book",
              "doc_count" : 20 // expected to get doc_count, sum by count field  
            },
            {
              "key" : "Book2",
              "doc_count" : 15 // expected to get doc_count, sum by count field  
            }
          ]
        }
      }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 14, 2020, 12:34pm UTC](https://discuss.elastic.co/t/use-custom-field-instead-of-doc-count/245234/2 "2020-09-14T12:34:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
