elasticitems
elasticitems copied to clipboard
Higher level client for Elasticsearch written in Node.js oriented on facets and simplicity
ElasticItems
Elasticsearch 7.x client for JS with faceted search, custom features and simple interface
Features
- faceted search
- full text
- pagination
- sorting
Getting Started
npm install elasticitems
const elasticitems = require('elasticitems')(es_config, search_config);
elasticitems.search()
.then(result => {
console.log(result);
})
API
var elasticitems = ElasticItems(es_config, [search_config])
es_config
The first es_config is elasticsearch configuration object and contains values like host, index or type.
search_config
Responsible for defining global configuration.
-
aggregationsfilters configuration i.e. fortags,actors,colors, etc. Responsible for generating facets. -
sortingsyou can configure different sortings liketags_asc,tags_descwith options and later use it with one key.
elasticitems.search(options, [search_config])
options
-
per_pageamount of items per page. -
pagepage number - used for pagination. -
queryused for full text search. -
operatorsearch operatorandandor(default). It works withqueryparameter -
sortused for sorting. one ofsortingskey -
filtersfiltering items based on specific aggregations i.e. {tags: ['drama' , 'historical']} -
query_stringi.e. "brand:Audi OR brand:Mercedes" -
facets_namesmake faceted search only for specific fields i.e. ['tags', 'genres'] -
fieldssearch only in specifc fields i.e. ['name', 'description']. Missing parameter means search in all fields -
idssearch by ids i.e. ['1', '2', '3'] -
exclude_idsexclude ids from search i.e. ['1', '2', '3']
elasticitems.similar(id, options)
Show similar items based on collaborative filtering
options
fieldsi.e ['tags'].
elasticitems.aggregation(options)
It returns full list of filters for specific aggregation
options
-
nameaggregation name -
per_pagefilters per page -
sizehow much load into memory (for pagination) -
pagepage number -
sortresponsible for sorting mechanism. It can be_countor_term -
orderresponsible for an order. It can beascordesc -
filtersfilter this aggregation through another aggregations (facets) -
aggregation_queryused for quering filters. It's not full text search -
querysearch through items -
query_stringsearch through items by query string i.e. (category:Garden and color:red)
elasticitems.get(id)
Returns found record otherwise throw an error
elasticitems.getBy(key, value)
Returns record based on key and value
elasticitems.add(data, [options])
Add a new object into index. Provide your own id if you don't want it auto-generated
elasticitems.partialUpdate(id, data, [options])
Updates object in index
elasticitems.delete(id)
Delete object from index
Notes
- Full text search does not work on
keywordtype because this type is not tokenized.keywordtype is great for faceted fields
Tests
npm test