Table of documentation contents

Aggregation Guide

You can use Weaviate’s Aggregation{} function to obtain meta information about collections of data.

Index

Basics

  • You can use the Aggregate{} function to get meta information about filtered groups in the data.
  • Some aggregate functions have (semantic) filters available.

Introduction

The Aggregate{} function can be used if you want to obtain meta information about the dataobjects in a Weaviate instance. Metainformation can be queried over all objects in a class (see Aggregate function), or by groups in a class.

Define a query

You can query Weaviate for semantic kinds based on standard GraphQL queries. The examples below only contain the GraphQL query. You can POST a GraphQL query to Weaviate as follows:

$ curl http://localhost/v1/graphql -X POST -H 'Content-type: application/json' -d '{GraphQL query}'

A GraphQL JSON object is defined as:

{
    "query": "{ # GRAPHQL QUERY }"
}

Aggregate Function

The Aggregate{} function is structured the following:

{
  Aggregate {
    <SematicKind> {
      <Class> {
        groupedBy {
            path
            value
        }
        meta {
          count
        }
        <propertyOfDatatypeString> {
            count
            type
            topOccurrences {
                value
                occurs
            }
        }
        <propertyOfDatatypeText> {
            count
            type
            topOccurrences {
                value
                occurs
            }
        }
        <propertyOfDatatypeNumberOrInteger> {
            count
            type
            minimum
            maximum
            mean
            median
            mode
            sum
        }
        <propertyOfDatatypeBoolean> {
            count
            type
            totalTrue
            totalFalse
            percentageTrue
            percentageFalse
        }
        <PropertyWithReference>
          pointingTo
          type
      }
    }
  }
}

An example query to obtain meta information about the data in the class City can be queried as follows. Note that the data is not grouped yet, the meta information is about all the data objects found with the class City.

{
  Aggregate {
    Things {
      Article {
        meta {
          count
        }
        InPublication {
          pointingTo
          type
        }
        wordCount {
          count
          maximum
          mean
          median
          minimum
          mode
          sum
          type
        }
      }
    }
  }
}

🟢 Click here to try out this graphql example in the Weaviate Playground.

More Resources

If you can’t find the answer to your question here, please use the:

  1. Knowledge base of old issues. Or,
  2. For questions: Stackoverflow. Or,
  3. For issues: Github.
  4. For Frequently Asked Questions.
Tags
  • Aggregate
  • GraphQL