I'm using Spring data Elasticsearch to parse data in ELasticseach. I have already there an indexed element (elastalert) witch contains the alert_sent property. So what i want to do is returning all alerts that were sent to the admin. I tried defining a method in the Repository List<Alert> findByAlert_sentTrue()
but it seems that the underscore is a problem (as mentioned in the documentation http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#repositories.query-methods.query-property-expressions).
Here' the mapping of the indexed element:
{
"elastalert_status" : {
"mappings" : {
"elastalert" : {
"properties" : {
"@timestamp" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"aggregate_id" : {
"type" : "string",
"index" : "not_analyzed"
},
"alert_exception" : {
"type" : "string"
},
"alert_info" : {
"properties" : {
"recipients" : {
"type" : "string"
},
"type" : {
"type" : "string"
}
}
},
"alert_sent" : {
"type" : "boolean"
},
"alert_time" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"match_body" : {
"type" : "object",
"enabled" : false
},
"rule_name" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
}
}
I created an entity to use that indexed element:
@Document(indexName = "elastalert_status", type = "elastalert")
public class Rule {
@Id
private String id;
private String name;
private String es_host;
private String es_port;
private String index;
private String type;
private String query;
private String TimeStamp;
private String email;
private int runEvery;
private String alertsent;
private String alertTime;
private String matchBody;
...
Getters and Setters
...
With Curl it would be
curl -XPOST 'localhost:9200/elastalert_status/elastalert/_search?pretty' -d '
{
"query": { "match": { "alert_sent": true } }
}'
So how can I get all those sent alerts using Spring Data Elasticsearch ? Thanks.