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

Add a switch to disallow slow queries #29050

Closed
jpountz opened this issue Mar 14, 2018 · 6 comments · Fixed by #51385
Closed

Add a switch to disallow slow queries #29050

jpountz opened this issue Mar 14, 2018 · 6 comments · Fixed by #51385
Assignees
Labels
>enhancement help wanted adoptme :Search/Search Search-related issues that do not fall into other categories

Comments

@jpountz
Copy link
Contributor

jpountz commented Mar 14, 2018

It has been requested a couple times that we add a switch to disable the use of slow queries. This is typically useful to administrators who would like to prevent some users from using most resources on a cluster.

What a slow query is still needs to be refined but I think we could start with the following definition:

  • multi-term queries that don't enforce at least the 5 first chars (eg. prefix queries with a length < 5, fuzzy queries, wildcard queries with a wildcard within the first 5 chars)
  • geo-shape queries
  • join queries
  • script queries

Basically this tries to include all queries that cannot efficiently skip and that need to collect all matches in a bitset to return an iterator. Plus the script query because if you run it on its own it will need to look at every single document of the index.

The threshold of 5 means that you could still run arbitrary prefix queries on fields that use the index_prefix optimization with default configuration.

Relates #11511

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@cbuescher
Copy link
Member

What a slow query is still needs to be refined

I talked to a user just recently and they built their own solution for sth. similar (I think it was a plugin) that basically intercepts each search request, inspects the query tree and then rejects some queries by a customizable rule that is application-dependent. Maybe this is too flexible for a start but might be worth thinking about later or as an alternative.

@jpountz
Copy link
Contributor Author

jpountz commented Mar 19, 2018

We discussed this in the search meeting and agreed on the following points:

  • this sounds useful
  • we want to start simple - finer-grained tuning will be done in follow-ups
  • the way it is wired should make it easy to bind the right to execute slow queries with roles of the logged user in the future

@colings86 colings86 added help wanted adoptme and removed discuss labels Mar 20, 2018
@polyfractal polyfractal added :Search/Search Search-related issues that do not fall into other categories and removed :Analytics/Aggregations Aggregations labels Jun 4, 2018
@anelson-vidscale
Copy link

How about a knob that requires user confirmation if a dashboard is opened with a time range larger than the knob specified date range? For example, I don't have any dashboards where looking back more than 3 weeks makes sense. I do have some indices where looking back 3 months makes sense.

Another, orthogonal option is to have a cancel button for every Kibana visualization/dashboard.
In general, the users are not malicious, and most of them are educated. In my experience the problem is accidental and the user realizes his mistake immediately and wishes there was a cancel button.

@jpountz
Copy link
Contributor Author

jpountz commented Oct 15, 2019

Another, orthogonal option is to have a cancel button for every Kibana visualization/dashboard.

FYI this is being somehow handled via #43332, which we plan to integrate in Kibana so that e.g. moving to a different window would cancel the loading of visualizations.

@matriv matriv self-assigned this Dec 9, 2019
matriv added a commit to matriv/elasticsearch that referenced this issue Jan 24, 2020
Add a new cluster setting `search.disallow_slow_queries` which by
default is `false`. If set to `true` then certain queries (prefix,
fuzzy, regexp and wildcard) that have usually slow performance cannot
be executed and an exception is thrown.

Closes: elastic#29050
@matriv
Copy link
Contributor

matriv commented Jan 27, 2020

Current status of slow queries guarded by disallowed_slow_queries setting, See #51385:

  • Fuzzy Query
  • Prefix Query
  • Regexp Query
  • Wildcard Query
  • Range queries on text/keyword fields
  • Geo-Shape Queries on 6.x PrefixTree geo shapes
  • Script Query
  • ScriptScore Query
  • Percolate Query
  • Joining Queries
    • NestedQuery
    • HasChildQuery
    • HasParentQuery
    • ParentIdQuery

matriv added a commit that referenced this issue Feb 12, 2020
Add a new cluster setting `search.allow_expensive_queries` which by
default is `true`. If set to `false`, certain queries that have 
usually slow performance cannot be executed and an error message
is returned.

- Queries that need to do linear scans to identify matches:
  - Script queries
- Queries that have a high up-front cost:
  - Fuzzy queries
  - Regexp queries
  - Prefix queries (without index_prefixes enabled
  - Wildcard queries
  - Range queries on text and keyword fields
- Joining queries
  - HasParent queries
  - HasChild queries
  - ParentId queries
  - Nested queries
- Queries on deprecated 6.x geo shapes (using PrefixTree implementation)
- Queries that may have a high per-document cost:
  - Script score queries
  - Percolate queries

Closes: #29050
matriv added a commit that referenced this issue Feb 12, 2020
Add a new cluster setting `search.allow_expensive_queries` which by
default is `true`. If set to `false`, certain queries that have
usually slow performance cannot be executed and an error message
is returned.

- Queries that need to do linear scans to identify matches:
  - Script queries
- Queries that have a high up-front cost:
  - Fuzzy queries
  - Regexp queries
  - Prefix queries (without index_prefixes enabled
  - Wildcard queries
  - Range queries on text and keyword fields
- Joining queries
  - HasParent queries
  - HasChild queries
  - ParentId queries
  - Nested queries
- Queries on deprecated 6.x geo shapes (using PrefixTree implementation)
- Queries that may have a high per-document cost:
  - Script score queries
  - Percolate queries

Closes: #29050
(cherry picked from commit a8b39ed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement help wanted adoptme :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants