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

es-query-pro

v1.0.0-beta.1

Published

Simple and powerful ElasticSearch query builder

Downloads

5

Readme

es-query-pro

NPM Link Build Status Code Coverage ISC License

Simple and powerful ElasticSearch query builder

Installation

npm install es-query-pro

Function reference

Basic

| Function | Match Type | Example | | -------------------------------------------- | ----------------- | ----------------------------------------------- | | term(fieldOrFields, valueOrValues, anyOrAll) | Exact field value | term('created_by', 123) | | matchBoostedPhrase(fields, terms, options) | Full-text | matchBoostedPhrase(['title'], 'AT&T Wireless') | | match(field, valueOrValues) | Full-text | match('title', 'Market research') | | exists(fieldOrFields) | Exact field | exists('deleted_at') | | range(field, op, value) | Exact field value | range('age', 'between', [18, 35]) |

Advanced

| Function | Match Type | Example | | ---------------------------------------------------- | ----------------- | ------------------------------------------------------------ | | multiTerm(fields, value, anyOrAll) | Exact field value | multiTerm(['created_by','modified_by'], 123) | | matchPhrase(field, phraseOrPhrases) | Full-text | matchPhrase('title', 'Little Red Riding Hood') | | matchPhrasePrefix(fieldOrFields, phraseOrPhrases) | Full-text | matchPhrasePrefix('title', 'Little Red R') | | multiMatch(fields, valueOrValues, anyOrAll) | Full-text | multiMatch(['title','body'], ['phone','mobile'], 'ALL') | | multiMatchWithPhrase(fields, valueOrValues, options) | Full-text | multiMatchWithPhrase(['title','body'], ['phone','mobile']) | | queryString(fieldOrFields, query) | Lucene expression | queryString('body', '(tech AND support) OR (service desk)') |

boostedPhrase??

Negative conditions

| Function | Match Type | Example | | ------------------------------------ | ----------------- | -------------------------------------------- | | notTerm(field, valueOrValues) | Exact field value | notTerm('status', [2,3,4]) | | notMultiTerm(fields, value) | Exact field value | notMultiTerm(['border','outline'], 'blue') | | notExists(fieldOrFields) | Exact field | notExists('category') | | notMatch(field, valueOrValues) | Full-text | notMatch('title', 'Market research') | | notMultiMatch(fields, valueOrValues) | Full-text | notMultiMatch(['title','body'], 'Research') | | notRange(field, op, value) | Exact field value | notRange('age', 'between', [36, 44]) |

Sorting and pagination

| Function | Example | | ------------------------- | ------------------- | | limit(limitTo) | limit(10) | | page(pageNo) | page(2) | | sort(field) | sort('-created_at') | | sortByRandom(trueOrFalse) | sortByRandom(true) |

Subqueries

| Function | Purpose | | --------------------- | ----------------------------- | | should(subquery) | Where subquery matches | | shouldNot(subquery) | Where subquery does not match | | shouldAny(subqueries) | Where any subquery matches |

Special functions

| Function | Purpose | | ------------------------------------------------ | ----------------------------------------------------------------------------- | | fields(fieldNames) | Set which fields to return. Default is ['*'] which returns all fields | | useHighlighter(definition) | Ask for excerpts of text near the matching terms | | includeFacets(forFields, limit) | Include counts for each field | | decayFunctionScore(definition) | Give match weight based on a bell-curve | | aggregateTerm(field, limit, exclusions) | A count of field values (like GROUP BY in SQL) | | dateHistogram(dateField, intervalName, timezone) | Aggregate matches by time periods | | clear(field) | Clear page, limit, must, mustNot, aggs, fields, highlighter, or functionScore |

Inspection

| Function | Purpose | | ------------ | -------------------------------------------- | | toKibana() | Get a string suitable for running in Kibana | | getFields() | Get the list of fields that will be returned | | getBody() | Get the structure of the query body | | getOptions() | Get the size, from, sort | | getQuery() | Return the fields, body and options to query |

Examples

const EsQueryBuilder = require('es-query-pro');

const query = new EsQueryBuilder();
query.term('author', 15);
query.matchBoostedPhrase(['fulltext_*'], 'Cold pressed juice');
query.range('created_at', '>=', '2021-01-01');
query.sort('created_at', 'desc');
query.limit(25);
query.page(2);
const textProcessor = new TextProcessor();
textProcessor.setArrayJoiner('ψ');
textProcessor.registerPattern(
	{ find: /([a-z])&([a-z0-9])/gi, replace: '$1ε$2' },
	{ find: /([a-z])ε([a-z0-9])/gi, replace: '$1&$2' }
);
textProcessor.registerField(/^fulltext_/);
QueryBuilder.registerProcessor(textProcessor);

Unit Tests and Code Coverage

Powered by jest

npm test
npm run coverage

Contributing

Contributions are welcome. Please open a GitHub ticket for bugs or feature requests. Please make a pull request for any fixes or new code you'd like to be incorporated.

License

Open Source under the ISC License.