Page tree
Skip to end of metadata
Go to start of metadata

Overview

Range facets are similar to Discrete Facets, except they aggregate facet value counts across all values in specified ranges. These ranges consist of a minimum value, a maximum value and a label.

Date Facets

 Date facets are a special case that are handled through a DateFacetRequest.

View incoming links.

Range Facet Example

A range facet request on Inflation Rate might look like this:

In this example, for the first range, the minimum value is 0 and the maximum value is 2.4 since the data type for the inflation rate field is a float. The label for the first range is "less than 2.4%".

Requesting Range Facets

The following sections describe how to request range facets using the Java and REST Query APIs.

Java Client API

Range Facets can be requested via the Java Client APIusing the RangeFacetRequest Note that multiple RangeFacetRequest objects can be added to the QueryRequest to request multiple facets.

The add methods for the RangeFacetRequest class support the ability to specify range facet ranges.

 

 

Example (Java)

Sample Java Client API code for creating a Range Facet request:

SearchClient client = ...;
QueryRequest query = new QueryRequest("*:*");

// Create a range facet request for a price field
RangeFacetRequest ranges = new RangeFacetRequest("price");
ranges.add("< $50", 0, 50);
ranges.add("$50 - $100", 50, 100);
ranges.add("$100 - $200", 100, 200);
ranges.add("> $200", 200, Integer.MAX_VALUE);
query.addFacet(ranges);

// Get the response
QueryResponse results = client.search(query);

// Display the price ranges
System.out.println("Price Ranges:");
for (FacetBucket bucket : results.getFacet("price")) {
  System.out.printf("%s - %d\n", bucket.getLabel(), bucket.getCount());
}

JSON REST API

See the REST API Tutorial for examples showing how to issue a JSON REST query. 

See the REST Query API page for details of composing JSON REST queries.

{
     "workflow": "search",
     "query": "*:*",
     "queryLanguage": "advanced",
     "locale": "en",
     "rows": 10,     
     "facets" : ["size(range=(\"< 150 \",0,150), range = (\"> 150 \",150,600),sortBy=COUNT, primarySort=ASC, minBucketCount=1)"],
     "fields": [ ".id", "title", "text", "date" ]     
}

XML REST Syntax

Syntax

rangeFacet=fieldname[(parameter1=value1[, parameter2=value2[, ...]])]

Parameters

Parameter

Type

Default Value

Description

range

complex

optional

See Range parameter

sortBy

enum (COUNT, VALUE)

COUNT

See Facet Bucket Sorting

primarySort

enum (ASC, DESC)

DESC

See Facet Bucket Sorting

secondarySort

enum (ASC, DESC)

ASC

See Facet Bucket Sorting

maxBuckets

integer

10

See Bucket Filtering

minBucketCount

integer

1

See Bucket Filtering. Count must be > 0.

distributedMaxBuckets

integer

-1 (unlimited)

See Bucket Filtering

distributedMinBucketCount

integer

1

See Bucket Filtering

statistics

boolean

false

See Facet Statistics

At least one range parameter must be specified for a rangeFacet in order to have any buckets returned

Range Parameter

The range parameter allows requesting a bucket for a specified range of values. This parameter can be specified multiple times in order to request counts for multiple ranges.

Its syntax is:

range=(label, lower, upper)

 

  • label - the label for the bucket that will be returned for this range (as a quoted string)
  • lower - the lower bounds for the range (or * for unbounded)
  • upper - the upper bounds for the range (or * for unbounded)

Examples (HTTP/REST)

// Create a range facet request for a price field
rangeFacet=price(range=("< $50", 0, 50), range=("$50 - $100", 50, 100), range=("$100 - $200", 100, 200), range=("> $200", 200, *))
  • No labels