Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asymmetrik/elastic-querybuilder

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asymmetrik/elastic-querybuilder - npm Package Compare versions

Comparing version 0.9.6 to 0.9.7

28

__tests__/QueryBuilder.test.js

@@ -112,5 +112,6 @@ const QueryBuilder = require('../src/index');

test('should place should filters inside a filter query', () => {
test('should place should filters inside a filter query if there is a must', () => {
const query = new QueryBuilder()
.raw('query.bool.boost', 1.2)
.must('match', 'city', 'South Park')
.should('match', 'name', 'Kenny')

@@ -128,2 +129,5 @@ .should('match', 'alias', 'Mysterion')

bool: {
must: {
match: { city: 'South Park' }
},
should: [

@@ -140,2 +144,24 @@ { match: { name: 'Kenny' }},

test('should place should filters at the top level if there are no other queries', () => {
const query = new QueryBuilder()
.raw('query.bool.boost', 1.2)
.should('match', 'name', 'Kenny')
.should('match', 'alias', 'Mysterion')
.build();
expect(query).toEqual({
from: 0,
size: 15,
query: {
bool: {
boost: 1.2,
should: [
{ match: { name: 'Kenny' }},
{ match: { alias: 'Mysterion' }}
]
}
}
});
});
test('should be able to build a compound boolean query', () => {

@@ -142,0 +168,0 @@ const query = new QueryBuilder()

2

package.json
{
"name": "@asymmetrik/elastic-querybuilder",
"version": "0.9.6",
"version": "0.9.7",
"description": "A query builder for Elasticsearch.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -164,4 +164,8 @@ const {

*/
hasShould () {
return this._queries.some((query) => query.type === BOOL.SHOULD);
shouldUseFilter () {
const types = this._queries.reduce((all, query) => {
if (all.indexOf(query.type) === -1) { all.push(query.type); }
return all;
}, []);
return types.indexOf(BOOL.SHOULD) > -1 && types.length > 1;
}

@@ -168,0 +172,0 @@

@@ -70,3 +70,3 @@ const BaseBuilder = require('./BaseBuilder');

// here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
const path = this.hasShould() ? 'query.bool.filter' : 'query';
const path = this.shouldUseFilter() ? 'query.bool.filter' : 'query';
applyRawParameter(this._query, path, super.build());

@@ -73,0 +73,0 @@ // Add filtered aggregations if we have any

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc