logstash metadata not passed to elasticsearch - elasticsearch

I am trying to follow the example https://www.digitalocean.com/community/tutorials/how-to-install-elasticsearch-logstash-and-kibana-elk-stack-on-centos-7
But the index name set by 30-elasticsearch-output.conf is not being resolved. In the example 30-elasticsearch-output.conf file:
index => "%{[#metadata][beat]}-%{+YYYY.MM.dd}"
In my case, the result elasticsearch index name is:
"%{[#metadata][beat]}-2016.09.07"
Only the date portion of the index name is set correctly.
What is responsible for setting the metadata value? I must have missed something in following the example.
This is related to a question asked earlier: ELK not passing metadata from filebeat into logstash

You can create index like this
index => "%{[beat][name]}-%{+YYYY.MM.dd}"
This would work definitely.

Related

Can't assign elastic search index for data stream

I am trying to create an index in elasticsearch using the index => option for elasticsearch logstash output running on docker:
output {
elasticsearch {
cloud_id => "..."
data_stream => "true"
ssl => "true"
api_key => "..."
document_id => "%{_log_id}"
index => "%{target_index}"
}
}
If I comment the index line, the pipeline works and data is sent to the default index. However, with the index defined (with or without it being a constant string) the following error is given on launch before ingesting any data
elasticsearch - Invalid data stream configuration, following parameters are not supported: {"index"=>"%{target_index}"}
Where target_index is an entry in the JSON body parsed in filter.
And breaks with Could not execute action: PipelineAction::Create<firmware_pipeline> indicating that this is before the pipeline is actually triggered.
Not sure if I'm just reading the docs wrong but this seems to be what others are doing as well.
Logstash version: 7.13.2
When you use a data stream, events are automatically routed to indexes based on values in the [data_stream] field. You cannot have automatic routing at the same time as explicit routing with the index => "%{target_index}" option. That is what the following is telling you:
following parameters are not supported: {"index"=>"%{target_index}"}
Remove the index option if you want to use a data stream. If you want explicit routing, remove the data_stream option.
If you need data to go to both destinations, use a second output.

nifi: How to specify dynamic index name when sending data to elasticsearch

I am new to apache NiFi.
I am trying to put data into elasticsearch using nifi.
I want to specify an index name by combining a specific string and the value converted from a timestamp field into date format.
I was able to create the desired shape with the expression below, but failed to create the index name with the value of the timestamp field of the content.
${now():format('yyyy-MM-dd')}
example json data
{
"timestamp" :1625579799000,
"data1": "abcd",
"date2": 12345
}
I would like to get the following result:
index : "myindex-2021.07.06"
What should I do? please tell me how
I know that if you use the PutElasticSearch Processor, you can provide it with a specific index name to use. And as long as the index name meets the proper ElasticSearch format for naming a new index, if the enable auto index creation in ElasticSearch is turned on, then when sent, Elastic will create the new index with the desired name. This has worked for me. Double check the Elastic Naming Rules that can be found here or https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-indexing.html

Elasticsearch index does not recognize date (Logstash pipeline)

I return with my doubts about elasticsearch.
I've been doing more testing and I'm almost done learning about ELK.
But I have a little problem. By creating a pipeline and outputting the elasticsearch cluster as follows:
output {
elasticsearch {
hosts => [ "IP:9200", "IP:9200", "IP:9200" ]
manage_template => false
index => "example-%{+yyyy.MM.dd}"
}
}
It does not correctly create the date. I have followed the indications of the documentation as it says: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-index
The above code creates the index: example-
Instead if I leave the default by unchecking the fields manage_template and index it create the index with the format correct: logstash-2020.08.17-000001
So I don't really know what I'm failing at. If it is a documentation issue or some other formatting error.
Another detail is that I have seen some examples from 2018 with the following format: index => "%{[#metadata][beat]}-%{+YYYY.MM.dd}". And reviewing the same previous link about the elasticsearch output plugin means creating different indexes, but I think it refers more to separating indexes according to a production or development space more than creating different indexes according to a date.
After a couple of days I have noticed that I changed the default name of the field #timestamp
Now it works correctly. Thank you

How to easily change a field from analyzed to non_analyzed

I have a hostname field that's coming in via filebeat to my logstash instance is getting passed to ElasticSearch where it's being treated as an analyzed field. That's causing issues, because the field itself needs to be reported on in it's totality.
Example: Knowing how many requests come to "prd-awshst-x-01" rather than splitting those out into prd, awshst, x, 01.
Does anyone have a lightweight way of doing this that can be used with visualizations?
Thanks,
We have to update mapping from analyzed to not_analyzed for specific field.
PUT/ mapping url/
{
property:{
field:{
text:"not_analyzed"
}
}
}
After updating the property please check is it reflected in mapping using GET method on mapping url.
Based on the title of your post, you already know that you need to change the mapping of the field to not_analyzed.
You should setup a template so that future indexes contain this mapping.
If you want to keep the existing data, you'll have to reindex it into a new index with the new mapping.
If you're using the default logstash template, it might be creating you a not_analyzed ".raw" field that you can use in visualizations in kibana.
The index template that is provided with Filebeat configures the hostname field as not_analyzed.
You should manually install the index template provided with Filebeat and then configure Logstash to write data to the Filebeat index as described in the docs.
This is what the elasticsearch output would look like. If you are processing other data through Logstash, then you might want to add a conditional around this output so that only beat events are sent via this output.
output {
elasticsearch {
hosts => "localhost:9200"
manage_template => false
index => "%{[#metadata][beat]}-%{+YYYY.MM.dd}"
document_type => "%{[#metadata][type]}"
}
}

Create a new index per day for Elasticsearch in Logstash configuration

I intend to have an ELK stack setup where daily JSON inputs get stored in log files created, one for each date. My logstash shall listen to the input via these logs and store it to Elasticsearch at an index corresponding to the date of the log file entry.
My logstash-output.conf goes something like:
output {
elasticsearch {
host => localhost
cluster => "elasticsearch_prod"
index => "test"
}
}
Thus, as for now, all the inputs to logstash get stored at index test of elasticsearch. What I want is that an entry to logstash occurring on say, 2015.11.19, which gets stored in logfile named logstash-2015.11.19.log, must be correspondingly stored at an index test-2015.11.19.
How should I edit my logstash configuration file to enable this ?
Answer because the comment can't be formatted and it looks awful.
Your filename ( I assume you use a file input ) is stored in your path variable as such:
file {
path => "/logs/**/*my_log_file*.log"
}
type => "myType"
}
This variable is accessible throughout your whole configuration, so what you can do is use a regex filter to parse your date out of the path, for example using grok, you could do something like that (look out: Pseudocode)
if [type] == "myType" {
grok {
match => {
"path" => "%{MY_DATE_PATTERN:myTimeStampVar}"
}
}
}
With this you now have your variable in "myTimeStampVar" and you can use it in your output:
elasticsearch {
host => "127.0.0.1"
cluster => "logstash"
index => "events-%{myTimeStampVar}"
}
Having said all this, I am not quite sure why you need this? I think it is better to have ES do the job for you. It will know the timestamp of your log and index it accordingly so you have easy access to it. However, the setup above should work for you, I used a very similar approach to parse out a client name and create sub-indexes on a per-client bases, for example: myIndex-%{client}-%{+YYYY.MM.dd}
Hope this helps,
Artur
Edit: I did some digging because I suspect that you are worried your logs get put in the wrong index because they are parsed at the wrong time? If this is correct, the solution is not to parse the index out of the log file, but to parse the timestamp out of each log.
I assume each log line for you has a timestamp. Logstash will create an #timestamp field which is the current date. So this would be not equal to the index. However, the correct way to solve this, is to mutate the #timestamp field and instead use the timestamp in your log line (the parsed one). That way logstash will have the correct index and put it there.

Resources