# Incorrect type of field in index from Logstash, why?

**URL:** <https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335>\
**Category:** Logstash\
**Created:** [February 15, 2021, 4:29pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335 "2021-02-15T16:29:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [February 15, 2021, 4:29pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/1 "2021-02-15T16:29:11Z")

</div>

Dears,

I loading tomcat logs to Elastic. My logstash config include such grok pattern:

```auto
 if "tomcat" in [tags] {
    grok {
      match => ["message", "%{IPV4} (?:-|%{USER:ident}) (?:-|%{USER:auth}) \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{NOTSPACE:request} (?:HTTP/%{NUMBER:httpversion})?|-)\" (?:HTTP%{NUMBER:response}) %{BASE10NUM:bytes_sent;number}B (%{BASE10NUM:response_time;number})ms\s+\((%{BASE10NUM:process_time;number})ms\)"]
    }
  }
  if "app" in [tags] {
    grok {
      match => ["message", "%{YEAR}.%{MONTHNUM}.%{MONTHDAY} %{TIME:time} \[%{DATA:application}] %{LOGLEVEL:logLevel} %{SPACE}*%{JAVACLASS:class} %{NOTSPACE} %{GREEDYDATA:app_msg}"]
    }
  }

```

Example lines from log file looks like:

```auto
10.181.231.53 - - [15/Feb/2021:13:11:32 +0100] "GET /v1/apps/X00004000001?terminal_type=VIRTUAL HTTP/1.1" HTTP200 318B 858ms (857ms)
10.181.231.53 - - [15/Feb/2021:13:33:44 +0100] "GET /v1/apps/X00004000001?terminal_type=VIRTUAL HTTP/1.1" HTTP200 318B 97ms (96ms)

```

Why Elasticsearch creates index where three last fields are strings instead of numeric fields like configuration in logstach??

Best Regards,  
Dan

---

<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:** [February 15, 2021, 5:26pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/2 "2021-02-15T17:26:15Z")

</div>

> [@d.silwon](#):
>
> `%{BASE10NUM:bytes_sent;number}`

That should be `%{BASE10NUM:bytes_sent:int}`. It will not take effect until you roll over to a new index.

---

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [February 15, 2021, 5:44pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/3 "2021-02-15T17:44:16Z")

</div>

Unfortunately I also tested it with pattern %{BASE10NUM:bytes\_sent:int} but the field in index was as a string.

---

<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:** [February 15, 2021, 6:25pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/4 "2021-02-15T18:25:20Z")

</div>

Did you create a new index? Once the type of a field in an index is set then it will not change.

---

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [February 15, 2021, 6:34pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/5 "2021-02-15T18:34:45Z")

</div>

Yes, the new index was created.

---

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [February 16, 2021, 1:19pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/6 "2021-02-16T13:19:37Z")

</div>

Solved for the help of mutate/convert plugin in Logstash config:

```auto
  if "tomcat" in [tags] {
    grok {
      match => ["message", "%{IPV4} (?:-|%{USER:ident}) (?:-|%{USER:auth}) \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{NOTSPACE:request} (?:HTTP/%{NUMBER:httpversion})?|-)\" (?:HTTP%{NUMBER:response}) %{BASE10NUM:bytes_sent;int}B (%{BASE10NUM:response_time;int})ms\s+\((%{BASE10NUM:process_time;int})ms\)"]
    }
  mutate {
        convert => {
                "bytes_sent" => "integer"
                "response_time" => "integer"
                "process_time" => "integer"
                }
        }
  }

```

Thanks a lot for your help and advice.

Best Regards,  
Daniel

---

<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:** [February 16, 2021, 5:30pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/7 "2021-02-16T17:30:39Z")

</div>

> [@d.silwon](#):
>
> `%{BASE10NUM:bytes_sent;int}`

That should be a colon, not a semicolon.

---

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [February 16, 2021, 5:55pm UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/8 "2021-02-16T17:55:28Z")

</div>

@Badger I'll check/test it tomorrow morning. Thanks for your advice.

---

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [February 17, 2021, 6:10am UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/9 "2021-02-17T06:10:37Z")

</div>

@Badger you are right. There was mistake in colon and semicolon. After corection and deletion of mutate/convert plugin from logstash config the index was created with proper types integer for fields "bytes\_sent", "bytes\_sent", "bytes\_sent". Thanks a lot.

---

<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:** [March 17, 2021, 6:11am UTC](https://discuss.elastic.co/t/incorrect-type-of-field-in-index-from-logstash-why/264335/10 "2021-03-17T06:11:12Z")

</div>

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