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.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

es-painless-fields Build Status

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 replace 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}

.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 © Vlad Holubiev

Keywords

FAQs

Package last updated on 16 Dec 2017

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