合并 query_string 和聚合
combine query_string and aggregations
我在一个索引中有来自不同应用程序的文档,应用程序名称在每个文档中都有一个字段。现在我想计算每天每个申请的文件数量。应用程序名称是字符串格式,所以我不能为它使用过滤器术语。
虽然下面的 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"
}
}
}
}
我在一个索引中有来自不同应用程序的文档,应用程序名称在每个文档中都有一个字段。现在我想计算每天每个申请的文件数量。应用程序名称是字符串格式,所以我不能为它使用过滤器术语。 虽然下面的 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"
}
}
}
}