When I index documents into Elasticsearch, the fields which conform to ECS are not being mapped correctly and all are being made into "text" fields, with "keyword" sub-fields.
What steps are needed to utilize ECS? I was under the impression from the docs that simply using a field named like fields in ECS, without other explicit mapping, would result in the fields being mapped as defined in ECS automatically. No need to define the ECS fields in your index template mapping definition...
This isn't happening. Even for fields which are coming from directly from beats without any modifications, like the agent.*
fields.
Here's some more detailed info:
We have a fairly typical Beats > Logstash > Elastic use case.
Filebeat is grabbing files from a directory. It doesn't do much except add a field with environment variable. Outputs from Filebeat is to Logstash.
In Logstash, we grok the message to get some custom fields, and then mutate some fields coming from Beats to match ECS and leave others untouched.
Here's the entire filter stage from our Logstash pipeline.
Here's a selection of the filter from our pipeline.
filter{
grok {
match => { "message" => "[grok pattern here]" }
}
date {
match => ["timestamp", "ISO8601"]
remove_field => ["timestamp"]
}
mutate{
add_field => { "[log][original]" => "%{[message]}" }
add_field => { "[file][path]" => "%{[log][file][path]}" }
remove_field => ["[log][file]"]
}}
Here is an example document which is being exported by Logstash:
{
"utility": {"name": "name"},
"file": {path": "somepath"},
"ecs": {"version": "1.4.0"},
"call_in": "1F 09",
"meter": {"irn": "12345"},
"input": {"type": "log"},
"host": {"name": "HOSTNAME"},
"@timestamp": "2020-03-14T17:52:34.045Z",
"agent": {
"id": "4b9f6ace-b9d0-453e-9939-95e02ec13e74",
"ephemeral_id": "94e9da7b-3983-492d-aecd-5f60468044fb",
"type": "filebeat",
"hostname": "HOSTNAME",
"version": "7.6.1"
},
"log": {
"offset": 0,
"flags": ["multiline"],
"original": "original message here"
},
"message": "original message here",
"tags": ["call-in"],
"@version": "1"
}
This is being fed into ElasticSearch.
output {
elasticsearch{
hosts => ["IPADDRESSHERE:9200"]
ilm_rollover_alias => "ls-call-in-alias"
ilm_pattern => "{now/d}-000001"
ilm_policy => "ilm-logs"
template_name => "template-ls-call-in"
}
In Elastic, we have an index template with mappings defined for our custom fields. None of the ECS fields are included. Here is the entire index template (named template-ls-call-in
as shown above):
{
"version": 0,
"index_patterns": ["ls-call-in-*"],
"settings": {
"number_of_shards": 1,
"number_of_replicas":0,
"index.lifecycle.name": "ilm-logs",
"index.lifecycle.rollover_alias": "ls-call-in-alias"
},
"mappings": {
"properties": {
"call-in":{"type": "keyword"},
"meter": {
"properties": {
"name":{"type": "keyword"},
"irn":{"type": "keyword"},
"type":{"type": "keyword"}
}
},
"utility": {
"properties": {
"name":{"type": "keyword"}
}}}}}
We have no other processing/pipelines being performed in elastic. We do all pipeline/processing via Logstash.
Our assumption was that these mappings would be formatted as shown, and the ECS fields would be formatted as defined in the docs, however after indexing the document into elastic, the mapping for all ECS fields is text with sub-keyword.
Here is a partial mapping, showing the agent.*
fields, which were left entirely untouched by our pipeline in Logstash:
{
"mapping": {
"_doc": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"agent": {
"properties": {
"ephemeral_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"hostname": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
Any ideas why the fields aren't using ECS mapping? Did we miss a configuration step somewhere? Does ECS not work with custom defined fields (contrary to what the docs say)?
This is a brand new install of 7.6.1 on Windows. Single node "cluster" for testing/dev purposes. (We're doing a rip and replace upgrade from 2.3.2.)
Let me know if I can provide any additional clarity on the issue. This is the first time we're using ECS. I can easily just define the fields manually in our mapping, but seems like that defeats the purpose?
Thanks all!