@kaliber/elasticsearch

2.1.2 • Public • Published

Elasticsearch

This package contains a custom render and a set of functions that can be used with @kaliber/build to build mappings. It also holds a set of util functions to query elasticsearch into a more readable format.

Installation

yarn add @kaliber/elasticsearch

Note This library is precompiled using kaliberjs/pack. Compiling it a second time will cause this library to stop working. This means for example that you should not add it to the compileWithBabel array of @kaliber/build.

Motivation

We like to write clean code. So whe made a set of util functions that help us create more readable mappings and write simple queries to send to the elasticsearch api.

The renderer is used for an internal plugin. So this is probably not that interesting for everybody. But the rest of the project can be used without it.

Usage of the utils

You can find more examples in the /examples folder.

*.mapping.js

import { text, keyword, object } from '@kaliber/elasticsearch/mapping'

export default {
  mappings: {
    dynamic: 'strict',
    properties: {
      id: keyword(),
      title: text(),
      taxonomy: object({
        title: text(),
        slug: keyword(),
      }),
    }
  }
}

example.js

import { filter, matchAll, term, search } from '@kaliber/elasticsearch/query'

const searchQuery = 'Waldo'
const taxonomy = 'books'

const query = and(
  searchQuery
    ? search(['title'], searchQuery),
    : matchAll(),
  filter(
    taxonomy && term('taxonomy.slug', taxonomy)
  )
)

Usage of the Renderer

To configure @kaliber/build to use the custom renderer in this package, you have to update the config/default.js file:

kaliber: {
  templateRenderers: {
    mapping: '@kaliber/elasticsearch/mapping-to-php-renderer'
  }
}

Releasing a new version

Because this library is used in both the node runtime and webpack environment, the library is precompiled using kaliberjs/pack. When releasing a new version, do not forget to execute yarn build before running yarn publish. This should be done because the yarn publish command uses your local files to upload to the npm registry.

Disclaimer

This library is intended for internal use, we provide no support, use at your own risk.

Readme

Keywords

none

Package Sidebar

Install

npm i @kaliber/elasticsearch

Weekly Downloads

4

Version

2.1.2

License

MIT

Unpacked Size

26.9 kB

Total Files

18

Last publish

Collaborators

  • nhoenderop
  • erwin-kaliber
  • melissabos18
  • janbru
  • albertkaliber
  • jerryduijm
  • hjsielcken
  • kaliber-owner
  • daveykropf
  • eecolor