gpt4 book ai didi

elasticsearch - 结合使用query_string和聚合

转载 作者:行者123 更新时间:2023-12-02 22:58:20 25 4
gpt4 key购买 nike

我在一个索引中包含来自不同应用程序的文档,每个文档中都有一个应用程序名称字段。现在,我想计算每个申请每天的文档数量。应用程序名称为字符串格式,因此无法为其使用过滤器术语。
下面的GET查询针对每个应用程序进行过滤

{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "+environmentType:prod +application:app1",
"analyze_wildcard": true
}
}
}
}
}

我可以将这种汇总用于简单的每日计数
{
"aggs": {
"simpleDatehHistogram": {
"date_histogram": {
"field": "timestamp",
"interval": "day"
}
}
}
}

我似乎无法将它们组合在一起,因此应用程序过滤器将应用于我的聚合结果。

这是我的索引的映射。
{
"myIndex" : {
"mappings" : {
"myType" : {
"properties" : {
"application" : {
"type" : "string"
},
"environmentType" : {
"type" : "string"
},
"event" : {
"properties" : {
"Id" : {
"type" : "long"
},
"documentId" : {
"type" : "string"
},
}
},
"hostname" : {
"type" : "string"
},
"id" : {
"type" : "string"
},
"timestamp" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"timestampEpoch" : {
"type" : "long"
},
"type" : {
"type" : "string"
},
"version" : {
"type" : "string"
}
}
}
}
}
}

最佳答案

使用它来结合它们:

{
"size":0,
"query":{
"filtered":{
"query":{
"query_string":{
"query":"+environmentType:prod +application:app1",
"analyze_wildcard":true
}
}
}
},
"aggs":{
"simpleDatehHistogram":{
"date_histogram":{
"field":"timestamp",
"interval":"day"
}
}
}
}

关于elasticsearch - 结合使用query_string和聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43932677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com