# Logstash "Could not index event to Elasticsearch"

**URL:** <https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181>\
**Category:** Logstash\
**Created:** [June 8, 2020, 1:34pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181 "2020-06-08T13:34:34Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdul\_Hameed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_hameed/32/46158_2.png) [@Abdul\_Hameed](https://discuss.elastic.co/u/Abdul_Hameed)\
**Post date:** [June 8, 2020, 1:34pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/1 "2020-06-08T13:34:35Z")

</div>

Hi,  
I am trying to index my data into Elasticsearch from logstash but I keep getting this type of errors for all indices.  
`2020-05-06T14:38:11,434][WARN][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"logstash-2020.05.06", :_type=>"doc", :routing=>nil}, #<LogStash::Event:0x343023b1>], :response=>{"index"=>{"_index"=>"logstash-2020.05.06", "_type"=>"doc", "_id"=>"32H-6XEBEechOczSU02t", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse field [Tax.amount] of type [text]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"Can't get text on a START_OBJECT at 1:1067"}}}}} `

Can you please help me in debugging the problem that is causing this to happen?  
Thanks and Regards

---

<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:** [June 8, 2020, 2:24pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/2 "2020-06-08T14:24:39Z")

</div>

A field in elasticsearch cannot be a keyword in some documents and an object in others. You are trying to index a document in which the [Tax.amount] field is an object into an index in which the [Tax.amount] field is a string.

---

<div class="post-metadata">

**Author:** ![Abdul\_Hameed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_hameed/32/46158_2.png) [@Abdul\_Hameed](https://discuss.elastic.co/u/Abdul_Hameed)\
**Post date:** [June 8, 2020, 2:47pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/3 "2020-06-08T14:47:32Z")

</div>

Thanks for the reply.  
How do I go about to resolve this, by filtering the object? Can you guide me how?  
Here is my pipeline.conf file which I am using:

```auto
input {
    udp {
        port => 5000
        type => syslog
    }
    udp {
        port => 5001
        type => json
    }
    tcp {
        port => 5001
        type => json
        ssl_enable => true
        ssl_key => "/etc/letsencrypt/live/elastic.acomodeo.com/privkey.pem"
        ssl_cert => "/etc/letsencrypt/live/elastic.acomodeo.com/fullchain.pem"
        ssl_extra_chain_certs => ["/etc/letsencrypt/live/elastic.acomodeo.com/chain.pem"]
        ssl_verify => false
        add_field => {"ssl" => "on"}
    }
}

## Add your filters / logstash plugins configuration here

filter {
    mutate {
      remove_field => ["port"]
    }

    if [type] == "syslog" {
        grok {
            match => { "message" => "\A%{TIMESTAMP_ISO8601:tmptimestamp}\|%{HOSTNAME:cluster}\|%{HOSTNAME:hostname}\|%{HOSTNAME:app}\|%{GREEDYDATA:message}\Z" }
           overwrite => ["message"]
        }
        date {
            match => ["tmptimestamp", "ISO8601"]
            remove_field => ["tmptimestamp"]
        }
    }

    if [type] == "json" {
        json {
            source => "message"
        }
        acologs {
        }
    }
}
output {

    if [type] == "syslog" and "_grokparsefailure" in [tags] {
        file { path => "~/log/failed_syslog_events-%{+YYYY-MM-dd}" }
    }

    elasticsearch {
        hosts => "localhost:9200"
    }
}

```

---

<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:** [June 8, 2020, 3:22pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/4 "2020-06-08T15:22:14Z")

</div>

> [@Abdul\_Hameed](#):
>
> How do I go about to resolve this, by filtering the object?

I suggest you read [this](https://discuss.elastic.co/t/problem-logstash-outputs-elasticsearch-could-not-index-event-to-elasticsearch-wazuh-alerts-3-x-2020-05-30/235038/6) post.

---

<div class="post-metadata">

**Author:** ![Abdul\_Hameed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_hameed/32/46158_2.png) [@Abdul\_Hameed](https://discuss.elastic.co/u/Abdul_Hameed)\
**Post date:** [June 9, 2020, 9:39am UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/5 "2020-06-09T09:39:23Z")

</div>

Thanks for the suggestion.  
I made the modification in my pipeline.conf by adding the line

```auto
if ! [host][name] {
	mutate {
	   rename { "[host]" => "[host][name]"	}
		}
            }

```

And now I'm getting the error -

```auto
[ERROR][logstash.agent] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of #, =>

```

What am I missing here?

Thanks

---

<div class="post-metadata">

**Author:** ![Abdul\_Hameed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_hameed/32/46158_2.png) [@Abdul\_Hameed](https://discuss.elastic.co/u/Abdul_Hameed)\
**Post date:** [June 9, 2020, 10:05am UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/6 "2020-06-09T10:05:57Z")

</div>

I found the missing part, there needs to be a =\> after rename, like this

```auto
if ! [host][name] {
	mutate {
	   rename => { "[host]" => "[host][name]"	}
		}
            }

```

But still I get the same error as before, did I miss something?

---

<div class="post-metadata">

**Author:** ![Abdul\_Hameed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_hameed/32/46158_2.png) [@Abdul\_Hameed](https://discuss.elastic.co/u/Abdul_Hameed)\
**Post date:** [June 10, 2020, 12:56pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/7 "2020-06-10T12:56:13Z")

</div>

Hi @Badger ,  
I also tried using the second solution as suggested in the other post by adding

```auto
mutate { replace => { "[host]" => "[host][name]" } }

```

I still am getting the errors same as the ones before:

```auto
[logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"logstash-2020.06.09", :_type=>"doc", :routing=>nil}, #<LogStash::Event:0x4fba72ab>], :response=>{"index"=>{"_index"=>"logstash-2020.06.09", "_type"=>"doc", "_id"=>"-VRFnnIBEechOczSRbyg", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse field [Rate.timeSpan] of type [text]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"Can't get text on a START_OBJECT at 1:539"}}}}}

```

I appreciate the help.  
Thanks

---

<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:** [June 10, 2020, 5:26pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/8 "2020-06-10T17:26:12Z")

</div>

> [@Abdul\_Hameed](#):
>
> [Rate.timeSpan]

In elasticsearch Rate.timeSpan is a text field, but in your events it is an object. You need to decide which one it should be and adjust accordingly.

---

<div class="post-metadata">

**Author:** ![Abdul\_Hameed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_hameed/32/46158_2.png) [@Abdul\_Hameed](https://discuss.elastic.co/u/Abdul_Hameed)\
**Post date:** [June 10, 2020, 5:59pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/9 "2020-06-10T17:59:10Z")

</div>

Thanks for the reply @Badger  
My apologies, I am just starting with Elastic stack.  
I need to define a filter for it specifically?  
Could you give me an example?

Thanks

---

<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:** [June 10, 2020, 6:03pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/10 "2020-06-10T18:03:26Z")

</div>

The post I linked to earlier explain what to do for the field host.name, you need to go through the same steps for Rate.timeSpan

---

<div class="post-metadata">

**Author:** ![Abdul\_Hameed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_hameed/32/46158_2.png) [@Abdul\_Hameed](https://discuss.elastic.co/u/Abdul_Hameed)\
**Post date:** [June 16, 2020, 9:31am UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/11 "2020-06-16T09:31:30Z")

</div>

Thanks @Badger,  
I will make the adjustments for Rate.timeSpan and check.

---

<div class="post-metadata">

**Author:** ![Abdul\_Hameed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_hameed/32/46158_2.png) [@Abdul\_Hameed](https://discuss.elastic.co/u/Abdul_Hameed)\
**Post date:** [July 1, 2020, 12:39pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/12 "2020-07-01T12:39:29Z")

</div>

Hi @Badger,  
I tried the solution you provided by adding this to my pipeline.conf file in logstash

```auto
if ! [Rate][timeSpan] {
	mutate {
	   rename { "[Rate]" => "[Rate][timeSpan]"	}
		}
            } 

```

But the error still persists.  
Can you please guide me in what I am doing wrong.

Best Regards

---

<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:** [July 29, 2020, 12:39pm UTC](https://discuss.elastic.co/t/logstash-could-not-index-event-to-elasticsearch/236181/13 "2020-07-29T12:39:32Z")

</div>

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