Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
simple-elastic-query
Advanced tools
Lightweight query builder for ElasticSearch
$ npm install elastic-query
const elasticQuery = require('elastic-query');
elasticQuery
.term('user.name', 'Foobaruser')
.build();
Currently, this query builder is only compatible with ElasticSearch 6.x.
This query builder covers most of the basics of the Query DSL and one compound query:
match_all
[query] (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html)match_none
[query] (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html)bool
Compound queryAnother important note is when you chain multiple queries, only the last query in the chain will be returned using build()
. If you use buildQueryArray()
then the query builder will return an array of Query
objects.
Summary:
build()
creates a leaf query clause.buildQueryArray()
creates a collection of queries that can be used in a compound query clause like bool
.elasticQuery.build()
This will create a leaf query of the last query operation performed on the query builder.
elasticQuery.buildQueryArray()
This will return an array of queries which can be used in compound queries.
elasticQuery.matchAll()
elasticQuery.matchNone()
elasticQuery.match(field, value, [options])
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
Type: Object
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.matchPhrase(field, value, [options])
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
Type: Object
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.matchPhrasePrefix(field, value, [options])
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
Type: Object
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.multiMatch(fields, value, [options])
Type: string[]
Fields you want to match.
Type: string
Value you want to match with the provided fields.
Type: Object
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.commonTerms(field, value, cutOff, [options])
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
Type: number
Terms are allocated to the high or low frequency groups based on the
cutoff_frequency
, which can be specified as an absolute frequency (>=1) or as a relative frequency (0.0 .. 1.0). source
Type: Object
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.queryString(field, value, [options])
Type: string
or string[]
Field(s) you want to match.
Type: string
Value you want to match with the provided field(s).
Type: Object
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.simpleQueryString(fields, value, [options])
Type: string[]
Fields you want to match.
Type: string
Value you want to match with the provided fields.
Type: Object
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.term(fields, value)
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.terms(field, values)
Type: string
Field you want to match.
Type: string[] | Object
Value you want to match with the provided field(s). Either an array of values you want to match the field with or options for terms lookup mechanism.
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.termsSet(field, [options])
Type: string
Field you want to match.
Type: Object
Additional query options.
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.range(field, values)
Type: string
Field you want to match.
Type: string[] | Object
Value you want to match with the provided field.
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.exists(field)
Type: string
Field you want to check if it exists.
elasticQuery.prefix(field, value, [boost])
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
Type: number
Value you want to match boost your query with.
elasticQuery.wildcard(field, value, [boost])
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
Type: number
Value you want to match boost your query with.
elasticQuery.regexp(field, value, [options])
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
Type: Object
Additional query options.
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.fuzzy(field, value, [options])
Type: string
Field you want to match.
Type: string
Value you want to match with the provided field.
Type: Object
Additional query options.
See the documentation of ElasticSearch for all the additional properties.
elasticQuery.type(type)
Type: string
Filters documents matching the provided document / mapping type.
elasticQuery.ids(values, [type])
Type: string
or string[]
Filters documents that only have the provided values as ids.
Type: string
Filters documents matching the provided document / mapping type.
elasticQuery.bool(options)
Type: Object
Boolean search options
Type: Object[]
must
clause, must be an array of queries.
Type: Object[]
filter
clause, must be an array of queries.
Type: Object[]
should
clause, must be an array of queries.
Type: Object[]
must_not
clause, must be an array of queries.
Type: number
Percentage of boost to boost the query with.
Type: number
If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. This behavior may be explicitly controlled by settings the minimum_should_match parameter. source
MIT © Simon Jang
FAQs
Lightweight query builder for ElasticSearch
The npm package simple-elastic-query receives a total of 0 weekly downloads. As such, simple-elastic-query popularity was classified as not popular.
We found that simple-elastic-query demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.