我正在尝试使用 Nest Code 从 ElasticSearch 的 json 日志下方获取 loglevel 和 logType 的值。LogLevel 应该是“ERROR” LogType 应该是“Response”。我该如何编写这个 Nest 查询。我认为Nest真的很难。
var settings = new connectionsettings(new uri("http://localhost:9200")).defaultındex("mylog-2019-07-29");
var client = new elasticclient(settings);
var searchresponse = client.search<rootobject>(s => s
.allındices()
.from(0)
.size(10)
.query(q => q
.match(m => m
.field(f => f.logLevel)
.query("Error")
)
));
var r3 = client.search<rootobject>(search => search.matchall().ındex("mylog-2019-07-29")).documents;
// OR
var result = client.search<rootobject>(q => q.allındices());
var result2 = result.hits;
using (httpclient client = new httpclient())
{
var result = await client.getasync("http://localhost:9200");
var data = jsonconvert.deserializeobject<list<rootobject>>(result.content.readasstringasync().result);
}
我怎么能用下面的json做到这一点?
{
"took": 72,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2968679,
"max_score": 1.0,
"hits": [
{
"_index": "slog-2019-07-29",
"_type": "logmessage",
"_id": "335af90f-6dab-459d-95f2-df09ffb15380",
"_score": 1.0,
"_source": {
"id": "335af90f-6dab-459d-95f2-df09ffb15380",
"parentLogId": "3ccf12bb-028e-498d-bc04-1394746c1d6f",
"logDate": "2019-07-29T11:05:04.0554493Z",
"logLevel": "Information",
"logSource": "TourService",
"logType": "Response",
"environment": "Production",
"sessionId": null,
"traceId": "d6dc979e-4ce6-4c16-8f8a-7ed41c1cd87a",
"klm": null,
"data": "{\"isSuccess\":true,\"code\":null,\"message\":null,\"data\":{\"xxxx\":{\"provider\":0,\......\"xxxxxxxx\":0.0}]}]}}}",
"processCost": 107.6808,
"urlMethod": "POST",
"urlPath": "/api/tour/get",
"urlQueryString": null,
"responseStatusCode": 200,
"headers": [
{
"key": "Content-Type",
"value": [
"application/json; charset=utf-8"
]
},
{
"key": "Request-Context",
"value": [
"appId=cid-v1:ec6df344-e1df-4097-bef4-69a3cce06eb6"
]
}
],
"additionalData": {}
}
},
{
"_index": "slog-2019-07-29",
"_type": "logmessage",
.....
....
..
.
我的索引地图:
{
"slog-2019-07-29": {
"mappings": {
"logmessage": {
"properties": {
"additionalData": {
"properties": {
"data": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"method": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"caller": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"correlationId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"data": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"environment": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"headers": {
"properties": {
"key": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"value": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"logDate": {
"type": "date"
},
"logLevel": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"logSource": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"logType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"parentLogId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"processCost": {
"type": "float"
},
"responseStatusCode": {
"type": "long"
},
"urlMethod": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"urlPath": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"urlQueryString": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}