elastic-builder
elastic-builder copied to clipboard
Runtime field script params
Issue
resolves https://github.com/sudo-suhas/elastic-builder/issues/201
Goal
Add support for Elasticsearch lang and params fields in runtime_mappings' script
Usage
This Typescript code:
const params = {
factor: 2
}
const field = esb.runtimeField("long", "emit(doc['measure'].value * params.factor);")
.lang('painless')
.params(params)
const reqBody = esb.requestBodySearch();
reqBody.runtimeMapping('measure', field);
Will generate this query:
{
"runtime_mappings": {
"measure": {
"type": "long",
"script": {
"lang": "painless",
"source": "emit(doc['measure'].value * params.factor);",
"params": {
"factor": 2
}
}
}
}
}
Changes in PR
- Add lang field to RuntimeField
- Add params field to RuntimeField
- Add unit tests
- Make RuntimeField return this to allow calls being chained and to make the it consistent with the rest of the API, as suggested on this comment.
@alejokf could you please resolve conflicts add tests to ensure 100% coverage? We need tests for the following:
- https://coveralls.io/jobs/141689187/source_files/25277366975#L82
- https://coveralls.io/jobs/141689187/source_files/25277366975#L95
@sudo-suhas conflicts are now fixed and coverage should be 100%