3 Tips to Elasticsearch Regular Expression

Mi Guoliang
  1. \d and \w are not supported in regexp query, so you have to use [0-9], [a-z], [A-Z], or [a-zA-Z] instead.

  2. In Painless Script Language which is the primary script language in Elasticsearch, String does not have function replaceAll, you should use Matcher.replaceAll instead, and almost all features are supported. Reference.

  3. Regular expression support is disabled by default in Elasticsearch, you should enable it by editing elasticsearch.yml. Add a line as below and restart your elasticsearch service:

script.painless.regex.enabled: true

If your Elasticsearch runs in cluster mode, you need update elasticsearch.yml in each node.

If you like my share, you can:

• Follow My Programming Experiences Page on Facebook.

• Follow My Twitter.

• Subscribe to my mail list.