# Upload logs within a date range

**URL:** <https://discuss.elastic.co/t/upload-logs-within-a-date-range/196871>\
**Category:** Logstash\
**Created:** [August 27, 2019, 5:03am UTC](https://discuss.elastic.co/t/upload-logs-within-a-date-range/196871 "2019-08-27T05:03:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ManuMP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manump/32/51842_2.png) [@ManuMP](https://discuss.elastic.co/u/ManuMP)\
**Post date:** [August 27, 2019, 5:03am UTC](https://discuss.elastic.co/t/upload-logs-within-a-date-range/196871/1 "2019-08-27T05:03:26Z")

</div>

We are using the following filter condition for uploading log entries. The filter will upload all log entries in the files. **We would like to restrict the upload of log entries within a date range and not all log entries. How can I do that?**

```
filter {

	if [type] == "connect300" {
		grok {
		  
		  match => { "message" => "\[%{NUMBER:LineNumber}]\[(?<logdate>%{MONTHNUM}/%{MONTHDAY}/%{YEAR} %{TIME})\]-%{GREEDYDATA:level}-\[ThreadId = %{NUMBER:ThreadID}, %{GREEDYDATA:Module}]-%{GREEDYDATA:Message}\r" }
		}
		
		date {
			match => ["logdate", "MM/dd/yyyy HH:mm:ss:SSS"]
			target => "@timestamp"
		}
	}
}
```

---

<div class="post-metadata">

**Author:** ![rugenl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rugenl/32/12887_2.png) [@rugenl](https://discuss.elastic.co/u/rugenl)\
**Post date:** [August 27, 2019, 2:43pm UTC](https://discuss.elastic.co/t/upload-logs-within-a-date-range/196871/2 "2019-08-27T14:43:26Z")

</div>

Not really pretty, but you could extract yyyy and mm from your logdate, then use logic like:

if [year] != "2019" and [mm] != "07" { drop {} }

These are character fields, so ranges would probably have to use regex. I don't do regex without study, but I think it would be something like [month] =~ "01|02|03", but don't use that without testing.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 27, 2019, 5:22pm UTC](https://discuss.elastic.co/t/upload-logs-within-a-date-range/196871/3 "2019-08-27T17:22:07Z")

</div>

You could try this

```
    mutate {
        add_field => {
            "[@metadata][start]" => "2019-08-27T01:02:03.004Z"
            "[@metadata][end]" => "2019-08-27T22:02:03.004Z"
        }
    }
    date { match => ["[@metadata][start]", "ISO8601" ] target => "[@metadata][start]" }
    date { match => ["[@metadata][end]", "ISO8601" ] target => "[@metadata][end]" }
    ruby {
        code => '
            start = event.get("[@metadata][start]").to_f
            finis = event.get("[@metadata][end]").to_f
            now = event.get("@timestamp").to_f
            unless now < finis and now > start
                event.cancel
            end
        '
    }
```

---

<div class="post-metadata">

**Author:** ![Ian\_Boje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ian_boje/32/52033_2.png) [@Ian\_Boje](https://discuss.elastic.co/u/Ian_Boje)\
**Post date:** [August 27, 2019, 7:14pm UTC](https://discuss.elastic.co/t/upload-logs-within-a-date-range/196871/4 "2019-08-27T19:14:21Z")

</div>

There is an 'age' filter for logstash that might do what you want. I've got a filter to drop messages greater than a day old:

```
filter {
  age {}
  if [@metadata][age] > 86100 {
    drop {}
  }
}

```

There might be some concern that this filter might be deprecated, as I don't see it in the current documentation. We've got a few devices that periodically send log entries from weeks ago; I think the OS forgets the time for a split second. The age filter helped me.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 24, 2019, 7:14pm UTC](https://discuss.elastic.co/t/upload-logs-within-a-date-range/196871/5 "2019-09-24T19:14:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
