@rule.js/elasticsearch

0.17.1 • Public • Published

Rule.js: Elasticsearch converter

Convert the Rule object into an elasticsearch query.

const ruleElasticsearch = require('@rule.js/elasticsearch')()
const Rule = require('@rule.js/core').extend({}, {
	elasticsearch: ruleElasticsearch
})

Rule()
	.or()
		.and().equal('name', 'foobar').gt('age', 20).end()
		.lt('age', 10)
	.end()
	.elasticsearch()

Outputs:

{
  "bool": {
    "must": [
      {
        "bool": {
          "should": [
            {
              "bool": {
                "must": [
                  {
                    "term": {
                      "name": "foobar"
                    }
                  },
                  {
                    "range": {
                      "age": {
                        "gt": 20
                      }
                    }
                  }
                ]
              }
            },
            {
              "range": {
                "age": {
                  "lt": 10
                }
              }
            }
          ]
        }
      }
    ]
  }
}

Package Sidebar

Install

npm i @rule.js/elasticsearch

Weekly Downloads

1

Version

0.17.1

License

MIT

Unpacked Size

22.1 kB

Total Files

10

Last publish

Collaborators

  • aghost7