/elastic-dsl-typescript

Typescript ElasticSearch search query builder

Primary LanguageTypeScriptGNU General Public License v3.0GPL-3.0

NPM

Library for generating queries (Elastic DSL) in the typescript language.

Support :
  • nested
  • script_fields
  • bool
  • query
  • aggregations
  • aggregations (ACTIVE\PASSIVE facet patern)

Generating hints based on types : type Based on the selected, the context of the prompts changes : bool_type After selecting the filter type, it shows options for a specific range_opts


range_params


Not all fields are currently implemented. But you can extend the support yourself in your code.*** range_params

Advanced exapmles in tests directory

example:
import { Bool, Query } from '../../index';

const q = new Query()
  .addProps('_source', ['field'])
  .addProps('explain', true)
  .addProps('from', 0)
  .addProps('size', 100)
  .addProps('q', 'Lucene query string ')
  .addQuery('match', {
    message: {
      query: 'query',
    },
  })
  .addQuery('term', {
    field: 'f',
    value: 'term',
  })
  .addQuery('range', {
    gt: 0,
    gte: 0,
  });

q.bool.addBuilder(
  'must',
  new Bool().add('must', 'term', {
    field: 'articul',
    params: {
      value: '111',
    },
  }),
);
result :
{
  "_source": ["field"],
  "explain": true,
  "from": 0,
  "q": "Lucene query string ",
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "articul": {
                    "value": "111"
                  }
                }
              }
            ]
          }
        }
      ]
    },
    "match": {
      "message": {
        "query": "query"
      }
    },
    "range": {
      "gt": 0,
      "gte": 0
    },
    "term": {
      "field": "f",
      "value": "term"
    }
  },
  "size": 100
}

TEST

npm run test