Use custom field instead of doc_count

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:

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

Output

    {
      "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:

    {
    "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  
            }
          ]
        }
      }

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