Hyperspace Docs
Hyperspace Homepage
  • Getting started
    • Overview
      • Hyperspace Advantages
      • Hyperspace Search
    • Quick Start
  • flows
    • Setting Up
      • Installing the Hyperspace API Client
      • Connecting to the Hyperspace Server
      • Creating a Database Schema Configuration File
        • Vector Similarity Metrics
        • Index Type Methods
      • Creating a Collection
      • Uploading Data to a Collection
      • Building and Running Queries
        • Building a Lexical Search Query
        • Building a Vector Search Query
        • Building a Hybrid Search Query
      • Retrieving Results
    • Data Collections
      • Uploading Data
      • Accessing Data
      • Supported Data Types
    • Queries
      • DSL Query interface
        • Aggregations
        • Bool Query
        • Candidate Generation and Metadata Filtering
        • Scoring and Ranking
  • Reference
    • Hyperspace Query Flow
    • Features and Benefits
    • Search Processing Unit (SPU)
    • Hyperspace Document Prototype
  • API Documentation
    • Hyperspace Client
      • add_batch
      • add_document
      • async_req
      • clear_collection
      • collections_info
      • commit
      • create_collection
      • delete_collection
      • delete_by_query
      • dsl_search
      • get_schema
      • get_document
      • reset_password
      • search
      • update_by_query
      • update_document
    • DSL Query Framework
      • Aggregations
        • Cardinality Aggregation
        • Date Histogram
        • Metric Aggregations
        • Terms Aggregation
      • Bool Queries
        • Free Text Search
        • 'match' Clause
        • 'filter' Clause
        • 'must' Clause
        • 'must_not' Clause
        • 'should' Clause
        • 'should_not' Clause
      • Candidate Generation and Metadata Filtering
        • Geo Coordinates Match
        • Range Match
        • Term Match
      • Scoring and Ranking
        • Boost
        • 'dis_max'
        • Function Score
        • Rarity Score (TF-IDF)
  • Releases
    • 2024 Releases
Powered by GitBook
On this page
  1. API Documentation
  2. DSL Query Framework
  3. Aggregations

Metric Aggregations

Metric Aggregations allow you to compute and analyze numeric measures on sets of documents. Metric aggregations operate on a numeric field in documents and produce a single numeric result for the specified metric.

To create a metric aggregation, follow the following template -

{
  "aggs": {
    "agg_name": {
      "metric_type": {
        "fieldname": "numeric_field"
      }
    }
  }
}

Where -

  • agg_name - aggregation results will be saved under this key

  • metric_type - the type of aggregation. Possible values are:

    • sum - Returns the sum of the field over the relevant candidates

    • min - Returns the min of the field over the relevant candidates

    • max - Returns the max of the field over the relevant candidates

    • avg- Returns the average of the field over the relevant candidates

    • count - Returns the total number of valid field entries in the relevant candidates

    • cardinality - Returns the total number of valid field values in the relevant candidates

    • percentiles - Returns the percentiles of the field over the relevant candidates.

  • fieldname - the name of the field to be used in the aggregation

Example 1 -

{
  "aggs": {
    "total_sales": {
      "sum": {
        "field": "sales"
      }
    }
  }
}

In the above example, the sum of the field "sales" will be calculated and stored under a key named "total_sales"

Example 2 -

{
  "aggs": {
    "unique_users": {
      "cardinality": {
        "field": "user_id"
      }
    }
  }
}

In the above example, the number of unique values of the field "user_id" will be calculated and stored under a key named "unique_users".

PreviousDate HistogramNextTerms Aggregation

Last updated 11 months ago