Aggregation

Aggregation means to count by some attribute. In this example, we count by document type contract.

This query produces count by _index.

You can only aggregate on either the _index or attributes that are type keyword. This includes:

  • name.raw
  • group_id
  • type
  • value

Ask support for a list of other keywords. (You cannot see this metadata [i.e., index mapping] yourself.)

You can count by any or the attributes returned by your query.

curl -X POST "https://www.lawinsider.com/api/v1alpha/search?token=$token&pretty" -H 'Content-Type: application/json' -d'{
    "query": {
  "bool": {
     "must": [
          {
              "simple_query_string": {
                  "default_operator": "or",
                  "fields": [
                      "name",
                      "snippet",
                      "body",
                      "company.name",
                      "jurisdiction.name"
                  ],
                  "query": "abc"
              }
          }
      ]
    }
  },
   "aggs": {
    "indices": {
      "terms": {
        "field": "_index", 
        "size": 10
      }
    }
  },
    "size": 1,
    "profile": false,
    "explain": false,
    "timeout": "15000ms",
    "_source": [
        "name",
        "snippet",
        "category.name",
        "category.value",
        "company.name",
        "company.value",
        "jurisdiction.name",
        "jurisdiction.value",
        "industry.name",
        "industry.value",
        "filing_date",
        "group_id",
        "group_size"
    ],
    "highlight": {
        "fields": {
            "name": {}
        },
        "order": "score",
        "post_tags": [
            "</b>"
        ],
        "pre_tags": [
            "<b>"
        ]
    }
}'

Produces:

{
  "took" : 14,
  "timed_out" : false,
  "_shards" : {
    "total" : 42,
    "successful" : 42,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 6042,
      "relation" : "eq"
    },
    "max_score" : 50.95735,
    "hits" : [
      {
        "_index" : "contract",
        "_type" : "_doc",
        "_id" : "en/bd7nRtG08le",
        "_score" : 50.95735,
        "_source" : {
          "snippet" : "This Agreement is entered into as of this 19th day of December, 2002 by and between MBNA AMERICA BANK, N.A., a national banking association having its principal place of business in Wilmington, Delaware (“MBNA”), and ABC BANCORP, a Georgia corporation having its principal place of business in Moultrie, Georgia (“ABC”), for themselves and their respective successors and assigns.",
          "group_size" : 1,
          "group_id" : "bd7nRtG08le",
          "filing_date" : "2003-03-31",
          "jurisdiction" : {
            "name" : "Delaware",
            "value" : "delaware-us"
          },
          "name" : "ABC BANCORP JOINT MARKETING AGREEMENT",
          "industry" : {
            "name" : "State commercial banks",
            "value" : "state-commercial-banks"
          },
          "company" : {
            "name" : "Abc Bancorp",
            "value" : "351569"
          },
          "category" : {
            "name" : "Abc Bancorp Joint Marketing Agreement",
            "value" : "abc-bancorp-joint-marketing-agreement"
          }
        },
        "highlight" : {
          "name" : [
            "<b>ABC</b> BANCORP JOINT MARKETING AGREEMENT"
          ]
        }
      }
    ]
  },
  "aggregations" : {
    "indices" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "contract",
          "doc_count" : 3397
        },
        {
          "key" : "clause",
          "doc_count" : 1929
        },
        {
          "key" : "definition",
          "doc_count" : 701
        },
        {
          "key" : "company",
          "doc_count" : 12
        },
        {
          "key" : "category",
          "doc_count" : 3
        }
      ]
    }
  }
}

Parameters and Attributes

aggs": {
          "_index": {
              "anyName": {
                  "_index": {
                      "terms": {
                          "field": "_index",
                          "size": 50
                      }
                  }
              },