I'm upgrading an older service that uses 'alerts' as indices within elastic search and runs the queries inside against 'logs' that have also been stored by other services
Looking at the portion that actually retrieves the 'alert' and runs the query the syntax has changed, for example there is no such thing as Nest.connection or the Post method.
public IList<AlertResult> CheckAlert(Alert alert)
{
var e = new Nest.Connection(new Nest.ConnectionSettings(_uri));
var r = e.Post("logs*/_search" +, GetQuery(alert));
JToken json = Newtonsoft.Json.Linq.JObject.Parse(r.Result.Result);
List<String> resultValues = new List<String>();
resultValues.AddRange(alertSource.ResultToken.Split('$'));
JToken val = null;
for (int i = 0; i < resultValues.Count; i++)
{
val = json.SelectToken(resultValues[i]);
}
var list = new List<AlertResult>();
if (val != null && val.HasValues)
{
if (val.Type == JTokenType.Array)
{
foreach (var item in val)
{
var resultValue = item.SelectToken(alertSource.ValueToken);
//dostuff
}
}
return list;
}
in order to get the Jtoken from the query I've been attempting to use the elasticsearch low level client, but I don't really understand what's going on, and what I get back, is not parsing in the same way. Is there a better way ? can anyone help me understand a bit better?!
var e = new ElasticClient(new Nest.ConnectionSettings(_uri).DefaultIndex(index));
var t = e.LowLevel.Search<byte[]>("logs@2017-08-24-14", "logentries", GetQuery(alert););
var str = System.Text.Encoding.Default.GetString(t.Body);
JToken json = Newtonsoft.Json.Linq.JObject.Parse(str);
contents of query string stored within an alert
{
"query": {
"filtered": {
"query": {
"match": {
"logLevel": 3
}
},
"filter": {
"bool": {
"must_not": {
"term": {
"logText": "initialized"
}
},
"must": {
"range": {
"created": {
"from": "2017-09-01T10:39:59",
"to": "2017-09-01T10:40:59"
}
}
}
}
}
}
}
}