[英]filter and return only specific fields in elasticsearch
我正在嘗試創建一個請求,我可以從 Elasticsearch 中提取特定指標,這樣我就可以更快地管理數據。 我通過以下請求擺脫了元數據和不必要的數據:
get localhost:9200/metricbeat-7.12.0/_search?size=2000&pretty&filter_path=hits.hits._source
{
"_source": ["@timestamp", "labels","prometheus"]
}
我得到了更接近我想要的東西。 現在我想要一個額外的過濾器,我只得到指標“prometheus.metrics.windows_cpu_time_total”而不是其他指標。
{
"hits": {
"hits": [
{
{
"_source": {
"@timestamp": "2021-04-29T15:35:57.518Z",
"prometheus": {
"metrics": {
"windows_service_status": 0
},
"labels": {
"instance": "localhost:9182",
"name": "timebrokersvc",
"job": "prometheus",
"status": "lost comm"
}
}
}
},
{
"_source": {
"@timestamp": "2021-04-29T15:35:57.518Z",
"prometheus": {
"metrics": {
"windows_cpu_time_total": 29480.625
},
"labels": {
"mode": "idle",
"core": "0,0",
"instance": "localhost:9182",
"job": "prometheus"
}
}
}
}}]}}
我嘗試了一個字段搜索,它似乎也不起作用。 有人可以指出我的查詢出了什么問題嗎?
{
"query": {
"match_all": {}
},
"fields": [
"prometheus.metrics",
{
"field": "windows_cpu_time_total"
}]
}
先感謝您
在 elasticsearch 版本 7.10 和 7.11 中, fields
功能為 beta 版本,如官方文檔中所述
但在 elasticsearch 版本 7.12 中, fields
選項工作正常
添加帶有索引數據、搜索查詢和搜索結果的工作示例
指數數據:
{
"@timestamp": "2021-04-29T15:35:57.518Z",
"prometheus": {
"metrics": {
"windows_cpu_time_total": 29480.625
},
"labels": {
"mode": "idle",
"core": "0,0",
"instance": "localhost:9182",
"job": "prometheus"
}
}
}
搜索查詢:
POST _search?size=2000&pretty&filter_path=hits.hits
{
"query": {
"match_all": {}
},
"fields": [
"prometheus.metrics.windows_cpu_time_total"
],
"_source": false
}
搜索結果:
{
"hits": {
"hits": [
{
"_index": "67588900",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"fields": {
"prometheus.metrics.windows_cpu_time_total": [
29480.625
]
}
}
]
}
}
這里是索引映射的概述
"prometheus": {
"properties": {
"*": {
"properties": {
"counter": {
"type": "object"
},
"histogram": {
"type": "object"
},
"rate": {
"type": "object"
},
"value": {
"type": "object"
}
}
"metrics": {
"properties": {
"*": {
"type": "object"
},
"windows_cpu_time_total": {
"type": "double"
},}}
@ECoder 我不能再發表評論了。 我會在這里回答你的問題。 以下是包含 Prometheus 屬性的映射概述。
"prometheus": {
"properties": {
"*": {
"properties": {
"counter": {
"type": "object"
},
"histogram": {
"type": "object"
},
"rate": {
"type": "object"
},
"value": {
"type": "object"
}
}
"metrics": {
"properties": {
"*": {
"type": "object"
},
"windows_cpu_time_total": {
"type": "double"
},}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.