使用NestJs删除旧的elasticsearch索引
green open ab_namespacename_namespaceid_appName_appId-2019.02.13 5
1 540 0 1.2mb 617kb
我有很多上述格式的日志,我想删除@timestamp
(在上面的日志(2019.02.13))范围内的旧日志(假设超过5天)。我已经通过查询删除了日志。
let query = {
index: '*',
headers: null,
body: {
query: {
filter: {
'@timestamp': {
'gte': 'now-5d',
},
},
},
},
};
try {
results = await this.elasticSearchClient.deleteByQuery(query);
console.log('results', results);
return results;
} catch (e) {
throw new LogHubException(e.message, HttpStatus.NOT_FOUND);
我有以下错误:
[parsing_exception] no [query] registered for [@timestamp], with { line=1 & col=42 }
注意:我使用NestJS来调用elasticsearch api,并使用elasticsearch [6.4]。我不想使用elasticsearch-curator。
回答如下:您的查询应如下所示:
{
"query": {
"range": {
"@timestamp": {
"gte": "now-5d"
}
}
}
}
在NestJS代码中相应地更新更改。
使用NestJs删除旧的elasticsearch索引
green open ab_namespacename_namespaceid_appName_appId-2019.02.13 5
1 540 0 1.2mb 617kb
我有很多上述格式的日志,我想删除@timestamp
(在上面的日志(2019.02.13))范围内的旧日志(假设超过5天)。我已经通过查询删除了日志。
let query = {
index: '*',
headers: null,
body: {
query: {
filter: {
'@timestamp': {
'gte': 'now-5d',
},
},
},
},
};
try {
results = await this.elasticSearchClient.deleteByQuery(query);
console.log('results', results);
return results;
} catch (e) {
throw new LogHubException(e.message, HttpStatus.NOT_FOUND);
我有以下错误:
[parsing_exception] no [query] registered for [@timestamp], with { line=1 & col=42 }
注意:我使用NestJS来调用elasticsearch api,并使用elasticsearch [6.4]。我不想使用elasticsearch-curator。
回答如下:您的查询应如下所示:
{
"query": {
"range": {
"@timestamp": {
"gte": "now-5d"
}
}
}
}
在NestJS代码中相应地更新更改。