I am trying to filter the documents using terms filter. I am not sure how to introduce wildcards in filter. I tried something like this:
"filter":{ "bool":{ "must":{ "terms":{ "wildcard" : { "aircraft":[ "a380*" ] } } } } }
But I get SearchParseException with this. Is there no way to use wildcard within filter framework?
A wildcard operator is a placeholder that matches one or more characters. For example, the * wildcard operator matches zero or more characters. You can combine wildcard operators with other characters to create a wildcard pattern.
Think of the Query DSL as an AST (Abstract Syntax Tree) of queries, consisting of two types of clauses: Leaf query clauses. Leaf query clauses look for a particular value in a particular field, such as the match , term or range queries. These queries can be used by themselves.
Frequently used filters will be cached automatically by Elasticsearch, to speed up performance. Filter context is in effect whenever a query clause is passed to a filter parameter, such as the filter or must_not parameters in the bool query, the filter parameter in the constant_score query, or the filter aggregation.
There are two wildcard expressions you can use in Kibana – asterisk (*) and question mark (?). * matches any character sequence (including the empty one) and ? matches single characters. Since these queries are performed across a large number of terms, they can be extremely slow.
The terms
filter doesn't support wildcards, queries do, though. Try this query instead
{ "query": { "bool": { "must": { "wildcard": { "aircraft": "a380*" } } } } }
Or if you absolutely need to use filters, you can try the regexp
filter, too:
{ "query": { "filtered": { "filter": { "bool": { "must": { "regexp": { "aircraft": "a380.*" } } } } } } }
UPDATE:
In latest ES versions, use the following query instead since filtered
has been removed:
{ "query": { "bool": { "filter": { "regexp": { "aircraft": "a380.*" } } } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With