Skip to main content

GeoDistanceOptionsFacet

Facet that provides a list of entries of ranges where each distance range has a number of hits associated. Great for finding results which are near to you.

Elasticsearch Mapping​

Below is an example mapping for the field metascore. We need to use a numeric type field type for this facet.

{
"properties": {
"location": {
"type": "geo_point"
}
}
}

Usage​

{
MultiQueryOptionsFacet
} from '@searchkit/sdk'

const searchkitConfig = {
...
facets: [
// example of Numeric Range
new GeoDistanceOptionsFacet({
field: 'location',
origin: '37.7749, -122.4194',
unit: 'mi',
ranges: [
{ to: 10, label: 'Very Close' },
{ from: 10, to: 20, label: 'Car ride away' },
{ from: 20, to: 100, label: 'A little far' }
],
label: 'location',
identifier: 'location'
})
]
}

const request = Searchkit(searchkitConfig);
const response = await request
.setFilters([
{
identifier: 'location',
value: 'Very Close'
}
])
.execute({
facets: true,
hits: {
size: 10,
from: 0,
},
});

Options​

OptionDescription
fieldAggregation field to be used, preferably a field that is raw, not tokenized
identifierRequired to be unique. Used to apply filters on field
labelUI label for facet. Used by @searchkit/elastic-ui components
displayOptional. Used on UI to specify what component to handle facet
rangesArray of distance options.
unitOptional. Unit of distance. Defaults to mi
originRequired. Origin point for distance calculation.