es-painless-fields
Advanced tools
Comparing version
13
index.js
@@ -23,2 +23,15 @@ 'use strict'; | ||
/** | ||
* Generates a script object which unsets fields on the _source document | ||
* @param {String[]} fields Arrray of field names to unset | ||
* @return {{lang: string, source: string, params: *}} Painless Script Object | ||
*/ | ||
unset(fields = []) { | ||
const source = fields.map(key => `ctx._source.remove('${key}')`).join(' '); | ||
return { | ||
lang: 'painless', | ||
source | ||
}; | ||
}, | ||
/** | ||
* Generates a script object which replaces fields on the _source document | ||
@@ -25,0 +38,0 @@ * @param {Object[]} fieldsReplacements Array of objects describing what to replace |
{ | ||
"name": "es-painless-fields", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Helpers for bulk update Elasticsearch documents by query using Painless scripts", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -17,2 +17,3 @@ # es-painless-fields [](https://travis-ci.org/vladgolubev/es-painless-fields)  | ||
* In-place **set** values to fields | ||
* In-place **unset** values to fields | ||
* In-place **replace** values in fields | ||
@@ -52,2 +53,10 @@ * **Zero** dependencies! | ||
### .unset(fields) | ||
#### fields | ||
Type: `String[]` | ||
Array of field names which you would like to unset. Example: `['a', 'b'']` | ||
### .replace(fieldsReplacements) | ||
@@ -54,0 +63,0 @@ |
5977
10.32%54
28.57%93
10.71%