Skip to content

Commit

Permalink
Move RuntimeField lang and params inside script
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Marulanda committed Apr 18, 2024
1 parent ec1d8b5 commit 219e949
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/core/runtime-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class RuntimeField {
* @returns {RuntimeField} returns `this` so that calls can be chained.
*/
lang(lang) {
this._body.lang = lang;
if (!isNil(this._body.script)) {
this._body.script.lang = lang;
}
return this;
}

Expand All @@ -91,7 +93,9 @@ class RuntimeField {
* @returns {RuntimeField} returns `this` so that calls can be chained.
*/
params(params) {
this._body.params = params;
if (!isNil(this._body.script)) {
this._body.script.params = params;
}
return this;
}

Expand Down
10 changes: 5 additions & 5 deletions test/core-test/request-body-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ test('Runtime mappging with lang and params', setsOption, 'runtimeMapping', {
propValue: {
test1: {
type: 'keyword',
lang: 'painless',
script: {
source: "emit(doc['my_field_name'].value * params.factor)"
},
params: {
factor: 2.0
lang: 'painless',
source: "emit(doc['my_field_name'].value * params.factor)",
params: {
factor: 2.0
}
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions test/core-test/runtime-field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ test('set script, lang and params', t => {
fieldA.params({ factor: 2.0 });
const expected = {
type: 'keyword',
lang: 'painless',
script: {
source: "emit(doc['my_field_name'].value * params.factor)"
},
params: {
factor: 2.0
lang: 'painless',
source: "emit(doc['my_field_name'].value * params.factor)",
params: {
factor: 2.0
}
}
};
t.deepEqual(fieldA.toJSON(), expected);
Expand Down

0 comments on commit 219e949

Please sign in to comment.