@honestdoor/es-utils
v0.2.34
Published
> TODO: description
Downloads
49
Readme
honestdoor-es-utils
Helpful utilities for working with elasticsearch + extended
Client
class with custom functions
Client
The client is an extention of the @elastic/elasticsearch
Client
. It adds additional functionality and better type safety to queries. As well as requiring _source
to be supplied in order to keep queries as effecient as possible.
Configuration
import { Client } from '@honestdoor/es-utils'
const { ES_ENDPOINT, ES_USER, ES_PASS } = process.env
const client = new Client({
node: ES_ENDPOINT,
auth: {
username: ES_USER,
password: ES_PASS
}
})
Example Usage
filter
Extended base search
function with additional fields to make filtering simpler and type safe.
import client from './client'
import { Property } from '@honestdoor/types'
import { rangeFilter, Filters } from '@honestdoor/es-utils'
const filters: Filters<Property> = {
cityName: termFilter("Edmonton"),
bedroomsTotal: rangeFilter({
gte: 3,
lte: 5
})
}
const { hits } = client.property.filter({
_source: ['id', 'cityName', 'bedroomsTotal'],
filters
})