Elasticsearch script.painless.regex.limit-factor Setting

Pulse - Elasticsearch Operations Done Right

On this page

Description Example Common Issues and Misuses Do's and Don'ts Frequently Asked Questions

The script.painless.regex.limit-factor setting in Elasticsearch controls the maximum number of states allowed in regular expression automata used within Painless scripts. This setting is crucial for maintaining performance and preventing potential denial-of-service attacks through complex regex patterns.

Description

  • Default value: 6
  • Possible values: Any positive integer
  • Recommendation: Keep the default value unless you have specific needs for more complex regex patterns

This setting multiplies the length of the input string by the specified factor to determine the maximum number of states allowed in the regex automaton. For example, with the default value of 6, a 100-character input string would allow up to 600 states in the regex automaton.

Increasing this value allows for more complex regex patterns but may impact performance and security. Decreasing it enhances security but may limit the complexity of allowed regex patterns.

Example

To change the script.painless.regex.limit-factor setting using the cluster settings API:

PUT _cluster/settings
{
  "persistent": {
    "script.painless.regex.limit-factor": 8
  }
}

This change would allow for more complex regex patterns in Painless scripts. For instance, it might be necessary when working with intricate text processing tasks that require sophisticated regex patterns. However, be cautious as it may also increase the risk of regex-based denial-of-service attacks.

Common Issues and Misuses

  • Setting the value too high can lead to performance issues and potential security vulnerabilities
  • Setting the value too low may cause legitimate regex patterns to fail unexpectedly
  • Misunderstanding the relationship between this setting and the input string length can lead to unexpected behavior

Do's and Don'ts

Do's:

  • Monitor performance when adjusting this setting
  • Test your scripts thoroughly after changing this value
  • Consider the security implications of allowing more complex regex patterns

Don'ts:

  • Don't set this value unnecessarily high
  • Don't ignore this setting when working with user-supplied regex patterns
  • Don't assume a higher value will always solve regex-related issues

Frequently Asked Questions

Q: How does the script.painless.regex.limit-factor affect performance?
A: A higher value allows for more complex regex patterns, which can potentially slow down script execution and increase memory usage. It's important to balance between the needed regex complexity and overall system performance.

Q: Can changing this setting break existing scripts?
A: Lowering the value might cause existing scripts with complex regex patterns to fail. Always test your scripts after modifying this setting.

Q: Is there a way to override this setting for individual scripts?
A: No, this setting applies cluster-wide and cannot be overridden for individual scripts. You need to consider the needs of all your scripts when adjusting this value.

Q: How does this setting relate to security in Elasticsearch?
A: This setting helps prevent regex-based denial-of-service attacks by limiting the complexity of regex patterns. A lower value enhances security but may restrict legitimate complex patterns.

Q: What happens if a regex pattern exceeds the allowed number of states?
A: If a regex pattern requires more states than allowed by this setting, Elasticsearch will throw an exception, preventing the script from executing.

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.