npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elasticitems

v2.0.15

Published

Faceted search client on top of Elasticsearch 7.x

Downloads

8

Readme

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.

  • aggregations filters configuration i.e. for tags, actors, colors, etc. Responsible for generating facets.

  • sortings you can configure different sortings like tags_asc, tags_desc with options and later use it with one key.

elasticitems.search(options, [search_config])

options

  • per_page amount of items per page.

  • page page number - used for pagination.

  • query used for full text search.

  • operator search operator and and or (default). It works with query parameter

  • sort used for sorting. one of sortings key

  • filters filtering items based on specific aggregations i.e. {tags: ['drama' , 'historical']}

  • query_string i.e. "brand:Audi OR brand:Mercedes"

  • facets_names make faceted search only for specific fields i.e. ['tags', 'genres']

  • fields search only in specifc fields i.e. ['name', 'description']. Missing parameter means search in all fields

  • ids search by ids i.e. ['1', '2', '3']

  • exclude_ids exclude ids from search i.e. ['1', '2', '3']

elasticitems.similar(id, options)

Show similar items based on collaborative filtering

options

  • fields i.e ['tags'].

elasticitems.aggregation(options)

It returns full list of filters for specific aggregation

options

  • name aggregation name

  • per_page filters per page

  • size how much load into memory (for pagination)

  • page page number

  • sort responsible for sorting mechanism. It can be _count or _term

  • order responsible for an order. It can be asc or desc

  • filters filter this aggregation through another aggregations (facets)

  • aggregation_query used for quering filters. It's not full text search

  • query search through items

  • query_string search 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 keyword type because this type is not tokenized. keyword type is great for faceted fields

Tests

npm test