Reproduce a query in elastalert with should/must/must_not
Hello everyone, I'm trying to adapt this query in a rules in elastalert but it doesn't really work for the moment
Elasticsearch request : GET /_search { "query": { "bool" : { "should" : [ {"match_phrase" : { "message" : "one sentence" }}, {"match_phrase" : { "message" : "another" }} ] } } }
Elastalert rules :
filter:
- query: bool: should: match_phrase: "message": "one sentence" match_phrase: "message": "another"
Have someone already solve this kind of problem ?
Thanks for your help
ElastAlert only does filter based queries, not scored, so should is not really used.
You probably want something like:
filter:
- query:
query_string:
query: "\"one sentence\" OR another"
default_field: message
Finally i find how to do it, this how I do to resolve my problem : filter:
- bool: should: - match_phrase: "message": "one sentence" - match_phrase: "message": "another"
The problem with using query_string instead of match_phrase is that it will match if there is "one" "another" or "sentence" for example :
- "one lsdkfjskljflksdjf" -> will match
- "sentence" -> will match
but what I need is to exactly match if the sentence contains "one sentence" or "another" :
- "one sentence qqslkdjsqkldjslkj" -> will match
- "one mqlkdqsmldkqmldksq" -> will not match
Maybe there is another way to do it but it's work for me, thanks for your help Qmando :)
If you keep the escaped quotation marks in the query string like I gave in my example, it will only match on full phrases. see https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-query-string-query.html