Unify and manage your data

Facet Search by Statistics Aggregation

Calculates statistics of attribute values: min, max, count, average, and sum.

General restrictions

The min, max, average, and sum values of aggregation operate on the double representation of the data. As a consequence, the result may be approximate when running on longs (fields with long type) whose absolute value is greater than 2^53.

Stats Aggregation

This type of aggregation calculates statistics of the attribute values min, max, count, average, and sum.

Table 1. Request Body Description
ParameterValueRequiredValue Type
fieldNameFacet attribute (same as facet in basic facet request)YesString
facetTypestatsYesENUM

Response Format

The response contains:

FieldTypeDescription
countlongAmount of values.
mindoubleMinimal value; not present if count=0.
maxdoubleMaximum value; not present if count=0.
avgdoubleAverage value; not present if count=0.
sumdoubleSum of values; not present if count=0.

Example

POST /api/{tenantId}/entities/_facets
                [
                {
                "fieldName": "attributes.height",
                "facetType": "stats"
                }
                ]
            

Response

{
  "attributes.height": {
    "count": 4,
    "min": 100.0,
    "max": 400.0,
    "avg": 202.5,
    "sum": 810.0
  }
}

Extended Stats Aggregation

The extended_stats aggregation is an extended version of the stats aggregation, where additional metrics are added such as the sum of squares, standard deviation (SD), variance, and SD bounds. In addition to stats aggregation, this can have input parameters.

By default, the extended_stats metric will return SD bounds, which provides an interval of plus/minus two standard deviations from the mean. If you want a different boundary, for example, three standard deviations, sigma can be specified as a request parameter.

Table 2. Input Parameters
ParameterValueRequiredValue Type
fieldNameFacet attribute (same as facet in basic facet request)YesString
facetTypeextended_statsYesENUM
sigmaNodouble

Response Format

The response contains:

FieldTypeDescription
countlongAmount of values.
mindoubleMinimal value; not present if count=0.
maxdoubleMaximum value; not present if count=0.
avgdoubleAverage value; not present if count=0.
sumdoubleSum of values; not present if count=0.
sum_of_squaresdoubleSum of squares; not present if count=0.
variancedoubleVariance of SD; not present if count=0.
std_deviationdoubleStandard deviation value; not present if count=0.
std_deviation_upper_bounddoubleSD upper bound; not present if count=0.
std_deviation_lower_bounddoubleSD lower bound; not present if count=0.

Example

POST /api/{tenantId}/entities/_facets
[
  {
    "fieldName": "attributes.height",
    "facetType": "extended_stats",
    "sigma": 3.0
  }
]

Response

{
 "attributes.height": {
   "count": 4,
   "min": 100.0,
   "max": 400.0,
   "avg": 202.5,
   "sum": 810.0,
   "sum_of_squares": 222100.0,
   "variance": 14518.75,
   "std_deviation": 120.49377577285891,
   "std_deviation_upper_bound": 443.4875515457178,
   "std_deviation_lower_bound": -38.48755154571782
 }
}

Min/Max/Sum/Avg/Count Aggregations

This type of aggregation is single value aggregation to find min/max/sum/avg value or amount of values.

Table 3. Request Body Description
ParameterValueRequiredValue Type
fieldNameFacet attribute (same as facet in basic facet request)YesString
facetTypeOne of the following: min, max, sum, avg, or valueCountYesENUM

Response Format

The response contains:

Table 4. Min Aggregation
FieldTypeDescription
mindoubleMinimal value; null if no data has matched.
Table 5. Max Aggregation
FieldTypeDescription
maxdoubleMaximum value; null if no data has matched.
Table 6. Avg Aggregation
FieldTypeDescription
avgdoubleAverage value; null if no data has matched.
Table 7. Sum Aggregation
FieldTypeDescription
sumdoubleSum of values; 0 if no data has matched.
Table 8. Count Aggregation
FieldTypeDescription
countlongCount of values; 0 if no data has matched.

Example

POST /api/{tenantId}/entities/_facets
[
  {
    "fieldName": "attributes.height",
    "facetType": "min"
  }
]

Response

{
  "attributes.height": {
    "min": 100.0
  }
}

Response (in case no data has matched)

{
  "attributes.height": {}
}

Faceted Search

Multiple faceted search