-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
featL Add support for runtime_mappings (#196)
runtime_mappings was added in Elasticsearch v7.11. Co-authored-by: Julien Maitrehenry <julien@kumojin.com>
- Loading branch information
1 parent
3de7f2d
commit 2572468
Showing
9 changed files
with
401 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"eslint.enable": true, | ||
"eslint.autoFixOnSave": true, | ||
"files.eol": "\n", | ||
"vsicons.presets.angular": false, | ||
"editor.detectIndentation": true, | ||
"[json]": { | ||
"editor.tabSize": 2 | ||
}, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
'use strict'; | ||
|
||
const isNil = require('lodash.isnil'); | ||
const validType = [ | ||
'boolean', | ||
'composite', | ||
'date', | ||
'double', | ||
'geo_point', | ||
'ip', | ||
'keyword', | ||
'long', | ||
'lookup' | ||
]; | ||
|
||
/** | ||
* Class supporting the Elasticsearch runtime field. | ||
* | ||
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html) | ||
* | ||
* Added in Elasticsearch v7.11.0 | ||
* [Release note](https://www.elastic.co/guide/en/elasticsearch/reference/7.11/release-notes-7.11.0.html) | ||
* | ||
* @param {string=} type One of `boolean`, `composite`, `date`, `double`, `geo_point`, `ip`, `keyword`, `long`, `lookup`. | ||
* @param {string=} script Source of the script. | ||
* | ||
* @example | ||
* const field = esb.runtimeField('keyword', `emit(doc['sessionId'].value + '::' + doc['name'].value)`); | ||
*/ | ||
class RuntimeField { | ||
// eslint-disable-next-line require-jsdoc | ||
constructor(type, script) { | ||
this._body = {}; | ||
this._isTypeSet = false; | ||
this._isScriptSet = false; | ||
|
||
if (!isNil(type)) { | ||
this.type(type); | ||
} | ||
|
||
if (!isNil(script)) { | ||
this.script(script); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the source of the script. | ||
* @param {string} script | ||
* @returns {void} | ||
*/ | ||
script(script) { | ||
this._body.script = { | ||
source: script | ||
}; | ||
this._isScriptSet = true; | ||
} | ||
|
||
/** | ||
* Sets the type of the runtime field. | ||
* @param {string} type One of `boolean`, `composite`, `date`, `double`, `geo_point`, `ip`, `keyword`, `long`, `lookup`. | ||
* @returns {void} | ||
*/ | ||
type(type) { | ||
const typeLower = type.toLowerCase(); | ||
if (!validType.includes(typeLower)) { | ||
throw new Error(`\`type\` must be one of ${validType.join(', ')}`); | ||
} | ||
this._body.type = typeLower; | ||
this._isTypeSet = true; | ||
} | ||
|
||
/** | ||
* Override default `toJSON` to return DSL representation for the `script`. | ||
* | ||
* @override | ||
* @returns {Object} returns an Object which maps to the elasticsearch query DSL | ||
*/ | ||
toJSON() { | ||
if (!this._isTypeSet) { | ||
throw new Error('`type` should be set'); | ||
} | ||
|
||
if (!this._isScriptSet) { | ||
throw new Error('`script` should be set'); | ||
} | ||
|
||
return this._body; | ||
} | ||
} | ||
|
||
module.exports = RuntimeField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.