将不在 ElasticSearch 中的数据返回为 doc_count 中的 0
Returning data that is not in ElasticSearch as 0 in doc_count
我在 ElasticSearch 中过滤。我希望 doc_count 到 return 0 非数据日期,但它根本不打印这些日期,只有带数据的日期 returned 给我。你知道我该怎么做吗?这是 Python 输出:
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
...
33479 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
33480 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
33481 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
33482 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
33483 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
这是我的 ElasticSearch 过滤器:
"from": 0,
"size": 0,
"query": {
"bool": {
"must":
[
{
"range": {
"@timestamp": {
"gte": "now-1M",
"lt": "now"
}
}
}
]
}
},
"aggs": {
"continent": {
"terms": {
"field": "source.geo.continent_name.keyword"
},
"aggs": {
"_source": {
"date_histogram": {
"field": "@timestamp", "interval": "8m"
}}}}}}
您需要将 min_doc_count
值设置为 0
以便聚合,其中您希望结果为零 doc_count
。
{
"from": 0,
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "now-1M",
"lt": "now"
}
}
}
]
}
},
"aggs": {
"continent": {
"terms": {
"field": "source.geo.continent_name.keyword",
"min_doc_count": 0
},
"aggs": {
"_source": {
"date_histogram": {
"field": "@timestamp",
"interval": "8m",
"min_doc_count": 0
}
}
}
}
}
}
我在 ElasticSearch 中过滤。我希望 doc_count 到 return 0 非数据日期,但它根本不打印这些日期,只有带数据的日期 returned 给我。你知道我该怎么做吗?这是 Python 输出:
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
...
33479 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
33480 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
33481 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
33482 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
33483 {'date': '2022-04-13T08:08:00.000Z', 'value': 7}
这是我的 ElasticSearch 过滤器:
"from": 0,
"size": 0,
"query": {
"bool": {
"must":
[
{
"range": {
"@timestamp": {
"gte": "now-1M",
"lt": "now"
}
}
}
]
}
},
"aggs": {
"continent": {
"terms": {
"field": "source.geo.continent_name.keyword"
},
"aggs": {
"_source": {
"date_histogram": {
"field": "@timestamp", "interval": "8m"
}}}}}}
您需要将 min_doc_count
值设置为 0
以便聚合,其中您希望结果为零 doc_count
。
{
"from": 0,
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "now-1M",
"lt": "now"
}
}
}
]
}
},
"aggs": {
"continent": {
"terms": {
"field": "source.geo.continent_name.keyword",
"min_doc_count": 0
},
"aggs": {
"_source": {
"date_histogram": {
"field": "@timestamp",
"interval": "8m",
"min_doc_count": 0
}
}
}
}
}
}