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

Allow reusing the same scripts in sorts, aggregations and script queries #48059

Closed
jpountz opened this issue Oct 15, 2019 · 6 comments
Closed
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team

Comments

@jpountz
Copy link
Contributor

jpountz commented Oct 15, 2019

Scripted queries and aggs provide a lot a flexibility. One downside however is that they require different kinds of scripts. It makes it challenging for Kibana to expose scripted fields.

Instead of expecting scripts of script queries to return a boolean, could we accept arbitrary search scripts and allow users to pass an expected value as well? This way the same scripts could be used in both queries and aggregations.

@jpountz jpountz added >enhancement :Search/Search Search-related issues that do not fall into other categories labels Oct 15, 2019
@elasticmachine
Copy link
Collaborator

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

@mayya-sharipova
Copy link
Contributor

Instead of expecting scripts of script queries to return a boolean, could we accept arbitrary search scripts and allow users to pass an expected value as well?

@jpountz This is not very clear to me. For example if we have a script "source": "doc['num1'].value * 10, is the idea that script query can run all different types of queries on these field values?

Do you have ideas how a potential API of this script query can look like?

@jpountz
Copy link
Contributor Author

jpountz commented Mar 6, 2020

@mayya-sharipova I think there are many options, we'd need to weigh pros and cons, e.g.

  • give existing queries (term, range, ...) a script parameter like we have on most aggregations so that they support scripts too
  • add more options to the existing script query to tell how to check whether the produced value matches
  • add ways to define fields as scripts as part of a search request, and allow these one-off scripted fields to be used in any query or aggregation

There might be other options I haven't thought of.

@mayya-sharipova
Copy link
Contributor

mayya-sharipova commented Mar 9, 2020

add ways to define fields as scripts as part of a search request, and allow these one-off scripted fields to be used in any query or aggregation

I wonder if we can reuse already existing script_fields parameter in the query phase as well.

{
  "query": {
    "range": {
      "price_in_usd": {
        "lte": 100
      }
    }
  },
  "script_fields": {
    "price_in_usd": {
      "script": {
        "source": "doc['price'].value * 1.25"
      }
    }
  }
}

@jpountz
Copy link
Contributor Author

jpountz commented Mar 9, 2020

I like the idea.

@rjernst rjernst added the Team:Search Meta label for search team label May 4, 2020
@javanna
Copy link
Member

javanna commented Jul 9, 2020

We are going to introduce support for runtime fields. The first implementation of them is going to be scripted runtime fields, which will address exactly the limitations mentioned in this issue, hence I am closing this in favour of #59332 .

@javanna javanna closed this as completed Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team
Projects
None yet
Development

No branches or pull requests

5 participants