All Projects → booleanapp → Elastic Muto

booleanapp / Elastic Muto

Licence: mit
Easy expressive search queries for Elasticsearch

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Elastic Muto

Serverless Appsync Plugin
serverless plugin for appsync
Stars: ✭ 804 (+3250%)
Mutual labels:  elasticsearch
Laravel Docker Elasticsearch
This is a simple repo for practicing elasticsearch with laravel and docker.
Stars: ✭ 18 (-25%)
Mutual labels:  elasticsearch
Kafka Connect Elasticsearch Source
Kafka Connect Elasticsearch Source
Stars: ✭ 22 (-8.33%)
Mutual labels:  elasticsearch
Datastream.io
An open-source framework for real-time anomaly detection using Python, ElasticSearch and Kibana
Stars: ✭ 814 (+3291.67%)
Mutual labels:  elasticsearch
Scalable Image Matching
This is a image matching system for scalable and efficient matching of images from a large database. The basic idea is to compute perceptural hash value for each image and compare the similarity based on the pHash computed. Searching are scalable with the elasticsearch as the backend database.
Stars: ✭ 17 (-29.17%)
Mutual labels:  elasticsearch
Elasticsearchdemo
ElasticSearch+Springboot的例子,对本机的文本等文件进行全文检索
Stars: ✭ 18 (-25%)
Mutual labels:  elasticsearch
Goodskill
🐂基于springcloud +dubbo构建的模拟秒杀项目,模块化设计,集成了分库分表、elasticsearch🔍、gateway、mybatis-plus、spring-session等常用开源组件
Stars: ✭ 786 (+3175%)
Mutual labels:  elasticsearch
Search Spring Boot Starter
ElasticSearch封装基于ES版本6.4.2,极大简化了ES操作难度
Stars: ✭ 23 (-4.17%)
Mutual labels:  elasticsearch
Great Big Example Application
A full-stack example app built with JHipster, Spring Boot, Kotlin, Angular 4, ngrx, and Webpack
Stars: ✭ 899 (+3645.83%)
Mutual labels:  elasticsearch
Fscrawler
Elasticsearch File System Crawler (FS Crawler)
Stars: ✭ 906 (+3675%)
Mutual labels:  elasticsearch
Szt Bigdata
深圳地铁大数据客流分析系统🚇🚄🌟
Stars: ✭ 826 (+3341.67%)
Mutual labels:  elasticsearch
Heroic
The Heroic Time Series Database
Stars: ✭ 836 (+3383.33%)
Mutual labels:  elasticsearch
Hugo Elasticsearch
Generate Elasticsearch indexes for Hugo static sites by parsing front matter
Stars: ✭ 19 (-20.83%)
Mutual labels:  elasticsearch
Demo Scene
👾Scripts and samples to support Confluent Demos and Talks. ⚠️Might be rough around the edges ;-) 👉For automated tutorials and QA'd code, see https://github.com/confluentinc/examples/
Stars: ✭ 806 (+3258.33%)
Mutual labels:  elasticsearch
Elasticsearch Readonlyrest Plugin
Free Elasticsearch security plugin and Kibana security plugin: super-easy Kibana multi-tenancy, Encryption, Authentication, Authorization, Auditing
Stars: ✭ 917 (+3720.83%)
Mutual labels:  elasticsearch
Springbootexamples
Spring Boot 学习教程
Stars: ✭ 794 (+3208.33%)
Mutual labels:  elasticsearch
Elasticsearch Query Builder
Build query for an ElasticSearch client using a fluent interface
Stars: ✭ 18 (-25%)
Mutual labels:  elasticsearch
Kafka Connect Elastic Sink
Kafka connect Elastic sink connector, with just in time index/delete behaviour.
Stars: ✭ 23 (-4.17%)
Mutual labels:  elasticsearch
Docker Kibana
Kibana Docker image including search-guard
Stars: ✭ 22 (-8.33%)
Mutual labels:  elasticsearch
Odsc 2020 nlp
Repository for ODSC talk related to Deep Learning NLP
Stars: ✭ 20 (-16.67%)
Mutual labels:  elasticsearch

elastic-muto

elastic-muto

Build Status Coverage Status

Easy expressive search queries for Elasticsearch with customisation! Build complicated elasticsearch queries without having to use the DSL. Expressions get compiled into native Elasticsearch queries, offering the same performance as if it had been hand coded.

elastic-muto is built using PEG.js. If you are curious about how the parsing works, check this out. The parser was originally developed for parsing filter conditions for the GET score API of Boolean.

Check out the API reference documentation.

Note: The library includes TypeScript definitions for a superior development experience.

Elasticsearch compatibility

elastic-muto can be used with elasticsearch v2.x and above.

Install

npm install elastic-muto --save

Usage

// Import the library
const muto = require('elastic-muto');

// muto.parse returns an elastic-builder BoolQuery object
const qry = muto.parse('["elasticsearch"] == "awesome" and ["unicorn"] exists');
qry.toJSON();
{
  "bool": {
    "must": [
      {
        "term": { "elasticsearch.keyword": "awesome" }
      },
      {
        "exists": { "field": "unicorn" }
      }
    ]
  }
}

Classes have also been provided for building the where expressions. Use whatever floats your boat 😉.

const qry = muto.parse(
    muto.where(muto.cn('elasticsearch').eq('awesome'))
        .and(muto.cn('unicorn').exists())
);

elastic-muto uses debug with the namespace elastic-muto. To enable debug logs, refer this.

Where Conditions

Where conditions can either be single(ex: '["key"] == value') or multiple. Multiple conditions can be combined with and/or.

Supported data types:

Data type Values Description
String "unicorns", "dancing monkeys" Strings are enclosed in double-quotes. Can contain space, special characters
Numbers 3, -9.5, "2.5" Numbers can be integers or floating point. Double quotes are also okay
Date "2016-12-01", "2011-10-10T14:48:00" Dates, enclosed within double quotes, must be in the ISO-8601 format
Boolean true, false, "true" Boolean can be true or false. Double quotes are also okay

Condition types:

Condition type Operator Data types Example
Equals == String, Number, Date ["elasticsearch"] == "awesome", ["answer"] == 42, ["launch_date"] == "2017-06-01"
Not Equals != String, Number ["joke_type"] != "knock-knock", ["downloads"] != 0
Contains contains String ["potion"] contains "fluxweed"
Not Contains !contains String ["anime"] !contains "fillers"
Less than < Number, Date ["num_idiots"] < 0, ["birthday"] < "1990-12-01"
Less than or equal to <= Number, Date ["issues"] <= 0, ["speed"] <= 299792458
Greater than > Number, Date ["contributos"] > 1, ["fictional_date"] > "2049-01-01"
Greater than or equal to >= Number, Date ["pull_requests"] >= 1, ["unfreeze_date"] >= "3000-01-01"
Boolean is Boolean ["prophecy"] is true
Property Exists exists Any data type ["unicorn"] exists
Property Missing missing Any data type ["clue"] missing

Both and, or cannot be used in the same level, because if you do, the desired query is not clear.

it('throws error if both and, or are called', () => {
    expect(
        () => muto.where()
            .and(muto.cn('anime').notContains('fillers'))
            .or(muto.cn('elasticsearch').eq('awesome'))
    ).toThrowError('Illegal operation! Join types cannot be mixed!');
});

Expressions can be nested using paranthesis. This allows to use both and, or:

const qry = muto.parse(
    '["elasticsearch"] == "awesome" and ["language"] == "node.js"' +
        'and (["library"] == "elastic-muto" or ["library"] == "elastic-builder")'
)

Elasticsearch Mapping

elastic-muto makes some assumptions for the mapping of data types. Following are the recommended mappings:

  • String mapping:

    {
    "type": "text",
      "fields": {
          "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    }
    

    This is the default since elasticsearch v5.x

  • Date mapping

    {
      "type": "date",
      "format": "strict_date_time_no_millis||strict_date_optional_time||epoch_millis"
    }
    
  • Number mapping

    { "type" : "double" }
    
  • Boolean mapping

    { "type": "boolean" }
    

If your mapping doesn't match, you might need to tweak the elasticsearch query generated with customisation.

Customisation

Elasticsearch queries generated by elastic-muto can be customised. Read more here. Check out a contrived example here.

REPL

Try it out on the command line using the node REPL:

# Start the repl
node ./node_modules/elastic-muto/repl.js
# Use the library loaded in context as `muto`
elastic-muto > muto.prettyPrint('["elasticsearch"] == "awesome" and ["unicorn"] exists')

API Reference

API reference can be accessed here - http://muto.js.org/docs.

API documentation was generated using documentation.js. It is being hosted with help from this awesome project - https://github.com/js-org/dns.js.org

Tests

Run unit tests:

npm test

The parser is tested extensively with upto 5 levels of nested queries!

Related

  • elastic-builder - An elasticsearch query body builder for node.js
  • FiltrES.js - A simple, safe, ElasticSearch Query compiler

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].