A simple query builder, it will helps to develop DSL query for Elasticsearch

Overview

Elasticsearch Dynamic Query Builder

A simple query builder, it will helps to develop DSL query for elasticsearch

Installation

You can start it from npm. Go to your terminal and run this command from your project root directory.

npm install elasticsearch-dynamic-query

After installation, import Elasticsearch Dynamic Query Builder in your file,

const { ElasticSearchDynamicQuery } = require('elasticsearch-dynamic-query');

Now you are ready to build your queries by your logical command.

Usage

Before build your query you need to develop your logical command based on your requirements. For building your logical command need to maintain a proper structure. Here is regular example,

const command = {
    fieldName: {
        type: DataTypeEnum, // ID, TEXT, NUMBER, ARRAY, DATETIME,
        conditions: {
            $eq?: any;
            $neq?: any;
            $in?: string[] | number[];
            $nin?: string[] | number[];
            $like?: any;
            $nlike?: any;
            $lt?: string | number;
            $lte?: string | number;
            $gt?: string | number;
            $gte?: string | number;
            $exists?: boolean;
            $regex?: string;
            $between?: {
                $lt?: string | number;
                $lte?: string | number;
                $gt?: string | number;
                $gte?: string | number;
            }
            $or?: {
              // Without $or, all conditional operator available under $or
            }
        }
    }
}

In your command you can pass multiple fields with type and conditions. Here is multiple accepatable data type and conditional operators.

Data type

This data type will be accept as type value in your field.

export enum DataTypeEnum {
  ID = 'ID',
  TEXT = 'TEXT',
  NUMBER = 'NUMBER',
  ARRAY = 'ARRAY',
  DATETIME = 'DATETIME',
}

Conditonal Operator

This conditional operator will be accept as conditions value in your field.

Operator Description
$eq Equal
$neq Not Equal
$in Included in an array
$nin Not included in an array
$like Match in text
$nlike Not match in text
$lt Less than
$lte Less than or equal to
$gt Greater than
$gte Greater than or equal to
$exists Exists field or not
$regex Supported regular expression
$between Is between
$or Or expression

Initialize Elasticsearch Dynamic Query Builder:

const builder = new ElasticSearchDynamicQuery(command);

List of Query

Compound Query

Compound queries wrap other compound or leaf queries, either to combine their results and scores, to change their behaviour, or to switch from query to filter context. Currently this package support these query under Compound Query:

Bool Query:

The default query for combining multiple leaf or compound query clauses, as must, should, must_not, or filter clauses. The must and should clauses have their scores combined — the more matching clauses, the better — while the must_not and filter clauses are executed in filter context. Below added example how to use Bool Query:

const query = builder.compoundQuery().build();

In default, Compound Query Build Bool query so no need to pass any type under compoundQuery() to build dynamic query. But compoundQuery(type) can accept other type.

This .build() function will generate a validate object using logical command

{
  "bool": {
    "must": [
      {
        "match": {
          "cast": "Antti"
        }
      }
    ],
    "filter": [
      {
        "range": {
          "release_year": {
            "lt": 2020,
            "gte": 2016
          }
        }
      }
    ]
  }
}

You can pass generated query to your searching index.

Contributing

Pull requests are welcome. For any changes, please open an issue first to discuss what you would like to change.

You might also like...

A tool that enables developers to connect multiple applications without the need to develop any interface.

Flooq A tool that enables developers to connect multiple applications without the need to develop any interface. Environments Env Service Status stagi

Jul 1, 2022

Quickly develop, deploy and test Solana programs from the browser.

Solana Playground SolPg allows you to quickly develop, deploy and test Solana programs(smart contracts) from the browser. Note SolPg is still in beta

Dec 29, 2022

This is a development platform to quickly generate, develop & deploy smart contract based applications on StarkNet.

This is a development platform to quickly generate, develop & deploy smart contract based applications on StarkNet.

generator-starknet This is a development platform to quickly generate, develop, & deploy smart contract based apps on StarkNet. Installation First, in

Nov 18, 2022

Weaver IBAX IDE. IBAX Network offers a polished development tool Weaver to develop DApps for ecoLibs (side chains).

Weaver Provide the user interface for ibax. Provide the IDE for App development. Save the private key of the user account and grant the permissions. R

Nov 4, 2022

A Typescript Hardhat-based template to develop evm-based smart contracts with all the tooling you need.

EVM-based Smart Contract Scaffold A Typescript Hardhat-based template to develop evm-based smart contracts with all the tooling you need. Features Use

Oct 24, 2022

SAP Community Code Challenge: This repository contains an empty OpenUI5 application and end-to-end tests written with wdi5. Take part in the challenge and develop an app that passes the tests.

SAP Community Code Challenge - UI5 The change log describes notable changes in this package. Description This repository is the starting point for the

Oct 24, 2022

A powerful, extensible, customizable & rapidly develop hacking framework.

YourN3xt(Beta) A powerful, extensible, customizable & rapidly develop hacking framework. Installations Github: https://github.com/OTAKKATO/YourN3xt N

Nov 21, 2022

It is an app that allows you to create lists of books and authors made in the course of Microverse. This project was develop using JavaScript, HTML and CSS.

AWESOME BOOKS This is an Awesome book store project that add store and diplay books on the UI. Built With HTML,CSS, JavaScript Frameworks Github, Lint

Jul 28, 2022

AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs UDEMY COURSE WITH DISCOUNTED - Step by Step Development of this Repository - https://www

Dec 17, 2022
Comments
  • $like operator isn't working as intended

    $like operator isn't working as intended

    I was trying to run a query to get some partial data from elasitcsearch. But it's returning an empty array. Tried query:

    {
            "name": {
                "type": "TEXT",
                "conditions": {
                    "$like": "tanvirr"
                }
            }
        }
    
    bug 
    opened by tanvirrb 1
Releases(0.4.0)
Owner
Hashemi Rafsan
Software Engineer
Hashemi Rafsan
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
The AKE-less General Purpose Build System with JavaScript DSL for Node.js platform.

The AKE-less General Purpose Build System with JavaScript DSL for Node.js platform. Inspired by NUKE. This project is reaching a mature stage, althoug

Aleksej Komarov 33 Oct 16, 2022
Crawler Crypto using NodeJS for performance with Elasticsearch DB for high efficiency.

Coin crawler - Coingecko version Crawler using NodeJS for performance with Elasticsearch DB for high efficiency. Requirements For development, you wil

Minh.N.Pham 1 Jan 20, 2022
The app's backend is written in Python (Flask) and for search it uses Elasticsearch. I used this app as candidate application for learning out how to build, run and deploy a multi-container environment (docker-compose).

foodtrucks-app-docker-compose The app's backend is written in Python (Flask) and for search it uses Elasticsearch. I used this app as candidate applic

Selçuk Şan 3 Oct 24, 2022
A movie schema sandbox for playing with EdgeDB and the EdgeQL query builder, pre-loaded with MCU data

The EdgeDB MCU sandbox ?? This is a sandbox for playing with EdgeDB and the EdgeQL query builder. It includes a simple movie database schema (dbschema

EdgeDB 13 Nov 9, 2022
100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

alloc 54 Dec 29, 2022
null 8 Nov 11, 2022
A simple library for Node and the browser that allows you to rapidly develop stateful, socketed multiplayer games and web applications.

gameroom.js Overview gameroom.js is a simple library for Node and the browser that allows you to rapidly develop stateful, socketed multiplayer games

Jackson Bierfeldt 3 Nov 3, 2022
A comprehensive collection of useful tools developed with the help of Ethers.js to interact with the Ethereum Blockchain to develop great DeFi apps as quickly and easily as possible.

hudi-packages-ethersfactory How to install Installing with npm For more information on using npm check out the docs here. npm i @humandataincome/ether

HUDI 6 Mar 30, 2022