File: regexp-filter.asciidoc

package info (click to toggle)
elasticsearch 1.6.2%2Bdfsg-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 59,348 kB
  • sloc: java: 461,436; xml: 1,913; python: 1,402; sh: 1,183; ruby: 618; perl: 172; makefile: 46
file content (61 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[[query-dsl-regexp-filter]]
=== Regexp Filter

The `regexp` filter is similar to the
<<query-dsl-regexp-query,regexp>> query, except
that it is cacheable and can speedup performance in case you are reusing
this filter in your queries.

See <<regexp-syntax>> for details of the supported regular expression language.

[source,js]
--------------------------------------------------
{
    "filtered": {
        "query": {
            "match_all": {}
        },
        "filter": {
            "regexp":{
                "name.first" : "s.*y"
            }
        }
    }
}
--------------------------------------------------

You can also select the cache name and use the same regexp flags in the
filter as in the query.

Regular expressions are dangerous because it's easy to accidentally
create an innocuous looking one that requires an exponential number of
internal determinized automaton states (and corresponding RAM and CPU)
for Lucene to execute.  Lucene prevents these using the
`max_determinized_states` setting (defaults to 10000).  You can raise
this limit to allow more complex regular expressions to execute.

You have to enable caching explicitly in order to have the
`regexp` filter cached.

[source,js]
--------------------------------------------------
{
    "filtered": {
        "query": {
            "match_all": {}
        },
        "filter": {
            "regexp":{
                "name.first" : {
                    "value" : "s.*y",
                    "flags" : "INTERSECTION|COMPLEMENT|EMPTY",
		    "max_determinized_states": 20000
                },
                "_name":"test",
                "_cache" : true,
                "_cache_key" : "key"
            }
        }
    }
}
--------------------------------------------------