Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime fields emit function doesn't work in lambda or functions #68235

Closed
nik9000 opened this issue Jan 29, 2021 · 3 comments
Closed

Runtime fields emit function doesn't work in lambda or functions #68235

nik9000 opened this issue Jan 29, 2021 · 3 comments
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement Team:Core/Infra Meta label for core/infra team

Comments

@nik9000
Copy link
Member

nik9000 commented Jan 29, 2021

Runtime fields are defined by a painless script, like, say:

"corrected_voltage": {
  "type": "double",
  "script": """
    for (double v : doc['voltage'].values) {
      emit(v + .2);
   }
  """

At the moment the emit function that isn't available in lambdas or function. So you can't do this:

"corrected_voltage": {
  "type": "double",
  "script": """
    void correctVoltage(double v) {
      emit(v + .2);
    }
    for (double v : doc['voltage'].values) {
      correctVoltage(v);
   }
  """

Or this:

"corrected_voltage": {
  "type": "double",
  "script": """
    doc['voltage'].values.stream().forEach(v -> emit(v +.2));
  """

These are both unfortunate but, at the moment, not show stopper issues. At least, we don't think they are because we wrote a ton of runtime field examples before we encountered the limitation. We'd like to get t working anyway though. Folks like lambdas and method are useful.

@nik9000 nik9000 added the :Search/Search Search-related issues that do not fall into other categories label Jan 29, 2021
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jan 29, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@javanna javanna added the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label Mar 3, 2021
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Mar 3, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Jun 17, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: elastic#69742
Refs: elastic#68235
stu-elastic added a commit that referenced this issue Jul 1, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: #69742
Refs: #68235
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Jul 1, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: elastic#69742
Refs: elastic#68235
Backport: e26fa4e
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Jul 1, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: elastic#69742
Refs: elastic#68235
Backport: e26fa4e
stu-elastic added a commit that referenced this issue Jul 1, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: #69742
Refs: #68235
Backport: e26fa4e
@javanna javanna removed :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team labels Jun 16, 2022
@stu-elastic
Copy link
Contributor

This was fixed by e9800bd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement Team:Core/Infra Meta label for core/infra team
Projects
None yet
Development

No branches or pull requests

5 participants