A newer version of this documentation is available.

View Latest

Search Facets

      +

      Facets are aggregate information collected on a particular result set. For any search, the user can collect additional facet information along with it.

      All the facet examples below, are for the query "water" on the beer-sample dataset. FTS supports the following types of facets:

      Term Facet

      A term facet counts how many matching documents have a particular term for a specific field.

      When building a term facet, use the keyword analyzer. Otherwise, multi-term values get tokenized, and the user gets unexpected results.

      Example

      • Term Facet - computes facet on the type field which has two values: beer and brewery.

        curl -X POST -H "Content-Type: application/json" \
        http://localhost:8094/api/index/bix/query -d \
        '{
            "size": 10,
            "query": {
                "boost": 1,
                "query": "water"
             },
            "facets": {
                 "type": {
                     "size": 5,
                     "field": "type"
                 }
            }
        }'

        The result snippet below only shows the facet section for clarity. Run the curl command to see the HTTP response containing the full results.

        "facets": {
            "type": {
                "field": "type",
                "total": 91,
                "missing": 0,
                "other": 0,
                "terms": [
                    {
                        "term": "beer",
                        "count": 70
                    },
                    {
                        "term": "brewery",
                        "count": 21
                    }
                ]
            }
        }

      Numeric Range Facet

      A numeric range facet works by the users defining their own buckets (numeric ranges).

      The facet then counts how many of the matching documents fall into a particular bucket for a particular field.

      Example

      • Numeric Range Facet - computes facet on the abv field with 2 buckets describing high (greater than 7) and low (less than 7).

        curl -X POST -H "Content-Type: application/json" \
        http://localhost:8094/api/index/bix/query -d \
        '{
            "size": 10,
            "query": {
                "boost": 1,
                "query": "water"
            },
            "facets": {
                "abv": {
                    "size": 5,
                    "field": "abv",
                    "numeric_ranges": [
                        {
                            "name": "high",
                            "min": 7
                        },
                        {
                            "name": "low",
                            "max": 7
                        }
                     ]
                }
            }
        }'

        Results:

        facets": {
            "abv": {
                "field": "abv",
                "total": 70,
                "missing": 21,
                "other": 0,
                "numeric_ranges": [
                    {
                        "name": "high",
                        "min": 7,
                        "count": 13
                    },
                    {
                        "name": "low",
                        "max": 7,
                        "count": 57
                    }
                ]
            }
        }

      Date Range Facet

      The Date Range facet is same as numeric facet, but on dates instead of numbers.

      Full text search and Bleve expect dates to be in the format specified by RFC-3339, which is a specific profile of ISO-8601 that is more restrictive.

      Example

      • Date Range Facet - computes facet on the ‘updated’ field that has 2 values old and new.

        curl -XPOST -H "Content-Type: application/json" -uAdministrator:asdasd http://<node>:8094/api/index/bix/query -d '{
        "ctl": {"timeout": 0},
        "from": 0,
        "size": 0,
        "query": {
                    "field": "country",
                    "term": "united"
        },
                "facets": {
                "types": {
                "size": 10,
                "field": "updated",
                "date_ranges": [
                {
                "name": "old",
                "end": "2010-08-01"
                },
                {
                "name": "new",
                "start": "2010-08-01"
                }
        ]
        }
        }
        }'

        Results

         "facets": {
                     "types": {
                        "field": "updated",
                        "total": 954,
                        "missing": 0,
                        "other": 0,
                     "date_ranges": [
                      {
                        "name": "old",
                        "end": "2010-08-01T00:00:00Z",
                        "count": 934
                      },
                      {
                        "name": "new",
                        "start": "2010-08-01T00:00:00Z",
                        "count": 20
                      }
                       ]
                     }
                   }