elastic-builder icon indicating copy to clipboard operation
elastic-builder copied to clipboard

Runtime field script params

Open alejokf opened this issue 2 years ago • 2 comments

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 avatar Apr 18 '24 15:04 alejokf

@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 avatar May 05 '24 12:05 sudo-suhas

@sudo-suhas conflicts are now fixed and coverage should be 100%

alejokf avatar May 06 '24 14:05 alejokf