我想对match_only_text类型字段上发生的消息数量进行计数和排序。使用DSL查询,输出必须如下所示:
{" Text message 1":615
" Text message 2":568
....}
所以我在基巴纳试试这个:
GET my_index_name/_search?size=0
{
"aggs": {
"type_promoted_count": {
"cardinality": {
"field": "message"
}
}
}
}
然而,我得到了这个错误:
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "match_only_text fields do not support sorting and aggregations"
}
我对“信息”领域感兴趣--这是它的映射:
"message" : {
"type" : "match_only_text"
}
这是索引映射的一部分:
"mappings" : {
"_meta" : {
"package" : {
"name" : "system"
},
"managed_by" : "ingest-manager",
"managed" : true
},
"_data_stream_timestamp" : {
"enabled" : true
},
"dynamic_templates" : [
{
"strings_as_keyword" : {
"match_mapping_type" : "string",
"mapping" : {
"ignore_above" : 1024,
"type" : "keyword"
}
}
}
],
"date_detection" : false,
"properties" : {
"@timestamp" : {
"type" : "date"
}
.
.
.
"message" : {
"type" : "match_only_text"
},
"process" : {
"properties" : {
"name" : {
"type" : "keyword",
"ignore_above" : 1024
},
"pid" : {
"type" : "long"
}
}
},
"system" : {
"properties" : {
"syslog" : {
"type" : "object"
}
}
}
}
}
}
}
请帮帮忙
发布于 2022-05-03 14:41:39
是的,从设计上看,match_only_text
属于text
字段类型家族,因此不能在其上进行聚合。
你需要:
在message.keyword
类型映射中创建一个keyword
子字段
PUT my_index_name/_mapping
{
"properties": {
"message" : {
"type" : "match_only_text",
"fields": {
"keyword": {
"type" : "keyword"
}
}
}
}
}
更新整个索引(使用_update_by_query
),以便填充子字段
POST my_index_name/_update_by_query?wait_for_completion=false
然后,根据索引的大小,定期调用GET _tasks?actions=*byquery&detailed
以检查任务的进度。
C.在该子字段上运行聚合。
POST my_index_name/_search
{
"size": 0,
"aggs": {
"type_promoted_count": {
"cardinality": {
"field": "message.keyword"
}
}
}
}
https://stackoverflow.com/questions/72100755
复制相似问题