Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es-painless-fields

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-painless-fields

Helpers for bulk update Elasticsearch documents by query using Painless scripts

  • 0.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

es-painless-fields CircleCI node

Helpers for bulk update Elasticsearch documents by query using Painless scripts

Install

$ yarn add es-painless-fields

Features & Motivation

The main purpose is to utilize _update_by_query Elasticsearch API most efficiently. API is limited to updating documents in-place by scripts, so you cannot rely on ES to replace document by passing partial parameters. This package aims to ease partial bulk document updates.

  • In-place set values to fields
  • In-place unset values to fields
  • In-place replace values in fields
  • In-place increment values in fields
  • In-place decrement values in fields
  • In-place multiply values in fields
  • In-place divide values in fields
  • Zero dependencies!
  • ... to be done

Usage

const esClient = require('elasticsearch').Client();
const painlessFields = require('es-painless-fields');

const script = painlessFields.set({a: 1, b: 2});

esClient.updateByQuery({
  conflicts: 'proceed',
  body: {
    query: {match_all: {}},
    script
  }
});

API

.set(fieldsMap)

fieldsMap

Type: Object

Object fields which you would like to set. Example: {a: 1, b: 2}

Also can be in a flat form, like {'a.b.c': 1}

.unset(fields)

fields

Type: String[]

Array of field names which you would like to unset. Example: ['a', 'b'']

.increment(fieldsMap)

fieldsMap

Type: Object

Object fields which you would like to increment. Example: {a: 1, b: 2}

Also can be in a flat form, like {'a.b.c': 1}

.decrement(fieldsMap)

fieldsMap

Type: Object

Object fields which you would like to decrement. Example: {a: 1, b: 2}

Also can be in a flat form, like {'a.b.c': 1}

.multiply(fieldsMap)

fieldsMap

Type: Object

Object fields which you would like to multiply. Example: {a: 1, b: 2}

Also can be in a flat form, like {'a.b.c': 1}

.divide(fieldsMap)

fieldsMap

Type: Object

Object fields which you would like to divide. Example: {a: 1, b: 2}

Also can be in a flat form, like {'a.b.c': 1}

.replace(fieldsReplacements)

fieldsReplacements

Type: Array

Array of objects describing what to replace. Example:

const fieldsReplacements = [
  {field: 'a', pattern: 'foo', substring: 'bar'},
  {field: 'b', pattern: 'hello', substring: 'world'}
];

Returns a script which replaces fields by pattern with substrings. Example:

{
  "lang": "painless",
  "source": "ctx._source.a = ctx._source.a.replace(params.patterns[0], params.substrings[0]); ctx._source.b = ctx._source.b.replace(params.patterns[1], params.substrings[1]);",
  "params": {
    "patterns": ["foo", "hello"],
    "substrings": ["bar", "world"]
  }
}

License

MIT © Shelf

Keywords

FAQs

Package last updated on 01 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc