Elasticsearch字段分为多个值

时间:2016-07-17 06:13:28

标签: ruby elasticsearch logstash kibana elastic-stack

我正在使用ELK堆栈来发送日志。 我正在处理的问题是其中一个字段分解为多个值 为了说清楚,对于现场产品,我的价值应该是:
Anti MalwareNew Anti VirusVPN-1 & FireWall-1等等。

然而,在跑步时:

curl --user admin:111111 -XPOST 'localhost:9200/filebeat-2016.07.14/_search?pretty' -d '
{
  "size": 0,
  "aggs": {
    "group_by_product": {
      "terms": {
        "field": "product",
        "script": "_value"
      }
    }
  }
}'

输出结果为:

{
  "size": 0,
  "aggs": {
    "group_by_product": {
      "terms": {
        "field": "product"
      }
    }
  }
}'
{
  "took" : 116,
  "timed_out" : false,
  "_shards" : {
    "total" : 20,
    "successful" : 20,
    "failed" : 0
  },
  "hits" : {
    "total" : 2624573,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "group_by_product" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 8748,
      "buckets" : [ {
        "key" : "1",
        "doc_count" : 2439769
      }, {
        "key" : "firewall",
        "doc_count" : 2439769
      }, {
        "key" : "vpn",
        "doc_count" : 2439769
      }, {
        "key" : "anti",
        "doc_count" : 166522
      }, {
        "key" : "malware",
        "doc_count" : 87399
      }, {
        "key" : "new",
        "doc_count" : 79123
      }, {
        "key" : "virus",
        "doc_count" : 79123
      }, {
        "key" : "blade",
        "doc_count" : 8249
      }, {
        "key" : "compliance",
        "doc_count" : 8249
      }, {
        "key" : "identity",
        "doc_count" : 5176
      } ]
    }
  }
}

因此值VPN-1 & FireWall-1分为vpnfirewall1

我看到它与分析字段有关,但我不能将字段定义为未分析,因为字段创建是动态的。

感谢。

1 个答案:

答案 0 :(得分:2)

您需要使用动态模板。请参阅here

您只需要确保动态创建的字段遵循特定模式,否则只需使用*,如果您希望它适用于所有字段。将分析仪设置为关键字。该分析仪按原样传递字符串。