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

Mark all scripted field queries as expensive #59658

Merged

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Jul 15, 2020

This will cause them to fail if you don't have permission to execute
expensive queries.

Relates to #59332

This will cause them to fail if you don't have permission to execute
expensive queries.
@nik9000 nik9000 added the :Search/Search Search-related issues that do not fall into other categories label Jul 15, 2020
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jul 15, 2020
Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a couple of nits, LGTM otherwise

private void checkAllowExpensiveQueries(QueryShardContext context) {
if (context.allowExpensiveQueries() == false) {
throw new IllegalArgumentException(
"queries cannot be executed against [script] fields while [" + ALLOW_EXPENSIVE_QUERIES.getKey() + "] is set to [false]."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use the constant from the mapper? content type I think it is called

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we rather throw ElasticsearchException also, and why doesn't the context expose a check method instead that accepts for instance a message? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we rather throw ElasticsearchException also, and why doesn't the context expose a check method instead that accepts for instance a message? :)

That would probably be a good choice.

I have no idea why we were throwing ElasticsearchException when we were. It feels like this is what IAE is for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why we were throwing ElasticsearchException when we were. It feels like this is what IAE is for.

I figured it out - we translate all exceptions thrown when building a query into a QueryShardException which is always a 400.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doesn't the context expose a check method instead that accepts for instance a message? :)

It really is a good idea. I took a look at it and, ironically, testing it is kind of a pain. I'll hold off on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we open issues for possible follow-up tasks that we don't want to spend time on right now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me give it another go this morning!

@Override
public Query existsQuery(QueryShardContext context) {
checkAllowExpensiveQueries(context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe one day we will a base class for runtime mapper field types that does this in one place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably!

@javanna javanna mentioned this pull request Jul 15, 2020
30 tasks
@nik9000 nik9000 merged commit 4ba86b1 into elastic:feature/runtime_fields Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants