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

Please don't forbid Math.abs(int/long) #5583

Closed
benjismith opened this issue Mar 27, 2014 · 2 comments
Closed

Please don't forbid Math.abs(int/long) #5583

benjismith opened this issue Mar 27, 2014 · 2 comments

Comments

@benjismith
Copy link

I just reviewed the pull request #5562 and I strongly disagree with the change.

I'm currently using this feature to implement _delta_ sorting. For example, given these documents:

{ "name" : "John",  "year" : 1975 }
{ "name" : "Jim",  "year" : 1976 }
{ "name" : "James",  "year" : 1977 }
{ "name" : "Jody",  "year" : 1978 }
{ "name" : "Josh",  "year" : 1979 }

Consider a query like this, where I want the 1977 results to come first, and then the 1978 and 1976 results next, and the the 1975 and 1979 results last:

{
  "query" : { "match_all" : {} },
  "sort" : [{
    "_script" : {
      "script" : "abs(1977-doc['year'].value)",
      "order" : "asc"
    }
  }]
}

I use this kind of trick all the time (it's very common in the higher-education domain), and it depends on absolute values for int & long values, so your pull request is going to break my code.

Wouldn't it make more sense to just throw a 400 BAD REQUEST when the query tries to do abs(Integer.MIN_VALUE) instead of removing the function entirely for integral types?

@dakrone
Copy link
Member

dakrone commented Mar 27, 2014

@benjismith I just tested this locally, forbidding Math.abs(...) in forbiddenapis does not prevent you from using it in scripts, I believe the forbiddenapis check is only during Elasticsearch compilation time.

@benjismith
Copy link
Author

Gotcha. My mistake! Thanks for the clarification :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants