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

elasto

v3.1.0

Published

ElasticSearch client

Downloads

57

Readme

Elasto Circle CI

Introduction

Elasto is a simple library to query Elasticsearch.

Topics

Installation

npm install elasto

Support

If you want to use this package with Elasticsearch 0.90, you should use 1.1.2. The versions >=2.X.X will only support Elasticsearch 1.X.X.

Getting started

More infos about the config options here.

var Elasto = require('elasto');
Elasto.config({
    host: 'localhost:9200',
});

Elasto provides a simple query interface for the common usecases. You can have access to the elasticsearch.js client via Elasto.client. The client gets instantiated when you set the config with a host.

Example

All-in-one example. Find more options on API.

Elasto.query({
      index: 'development',
      type: 'tweets'
})
.near({ // documents near this location
    lat: 51.5,
    lon: -0.1467912,
    radius: 3
})
.where('name', 'London') // where name matches London
.size(2) // return only 2 documents
.from(1) // skip 1 document (searching after 1 document)
.fields('name', 'address') // return only name and address fields
.exec()
.then(function (res) { // execute
   // done!
});

API

Basic query

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.exec();

Fields matching

  • .where

.where accepts two types of arguments. Either an object with the fields to match.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.where({ username: '@jack'})
.exec();

Or key value pair of arguments

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.where('username', '@jack')
.exec();

Term

  • .term

Search a term.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.term('#love')
.exec();

Size

  • .size
  • .limit

Limit the size of the query.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.limit(3)
.exec();

Sort

  • .sort
  • .limit

Sorts the query by a field the size of the query.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.sort('description', 'asc')
.exec();

You can also sort by distance. It will sort based on the location field in the document.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.sort('distance', {
    lat: 51.5,
    lon: -0.1467912,
})
.exec();

Distance

  • .near

Finds documents in an area. The radius is in miles.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.near({
    lat: 51.5,
    lon: -0.1467912,
    radius: 2
})
.exec();

From

  • .from
  • .offset

Skips documents in the query.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.from(3)
.exec();

Range

  • .range

Find documents where the field matches a range.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.range('characters', [120, 150])
.exec();

You can also query the distance range. It will sort based on the location field in the document. All the distances are in miles.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.range('distance', {
    lat: 51.5,
    lon: -0.1467912,
    from: 2,
    to: 3
})
.exec();

Fields

  • .fields

Only return the specific fields.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.fields(['name', 'id'])
.exec();

Exclude

  • .exclude
  • .not

Excludes documents where the query gets matched (opposite of .where).

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.not('username', '@hater666')
.exec();

Count

Count documents based on a query

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.count();

Raw ElasticSearch Query

Returns the raw ElasticSearch computed by Elasto. You can directly use that object with the ElasticSearch node library (that's how Elasto is designed). Takes search or count as argument. If empty, the raw query will be search.

Elasto.query({
    index: 'development',
    type: 'tweets'
})
.raw(); 
// Returns Object
// -> { index: 'development',
//  type: 'tweets',
//  body: { query: { filtered: [Object] } } }

License

elasto is released under the MIT license. See LICENSE.txt for the complete text.

Contributors