# Can’t create a new index in elasticsearch

**URL:** <https://discuss.elastic.co/t/can-t-create-a-new-index-in-elasticsearch/122064>\
**Category:** Elasticsearch\
**Created:** [March 1, 2018, 1:18pm UTC](https://discuss.elastic.co/t/can-t-create-a-new-index-in-elasticsearch/122064 "2018-03-01T13:18:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![geppo](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@geppo](https://discuss.elastic.co/u/geppo)\
**Post date:** [March 1, 2018, 1:18pm UTC](https://discuss.elastic.co/t/can-t-create-a-new-index-in-elasticsearch/122064/1 "2018-03-01T13:18:14Z")

</div>

hi, i'm new in logstash and I would try to index my apache logs in elasticsearch 5.4.3. I have followed this guide on official es blog: [https://www.elastic.co/blog/logstash\_lesson\_elasticsearch\_mapping](https://www.elastic.co/blog/logstash_lesson_elasticsearch_mapping)

When I try to create an index with that command:  
`head -50 /var/log/apache2/access_log | /usr/share/logstash/bin/logstash -f above_sample.conf`  
I get this error:  
`11:59:53.998 [[main]>worker4] WARN logstash.outputs.elasticsearch - Could not index event to Elasticsearch. {:status=>404, :action=>["index", {:_id=>nil, :_index=>"my_index", :_type=>"mytype", :_routing=>nil}, 2018-02-25T11:08:51.000Z michele-desktop %{message}], :response=>{"index"=>{"_index"=>"my_index", "_type"=>"mytype", "_id"=>"AWHhN-FTij9MjQt45fC4", "status"=>404, "error"=>{"type"=>"type_missing_exception", "reason"=>"type[mytype] missing", "index_uuid"=>"PMwuOKH7SuGlU-B90UaQiA", "index"=>"my_index", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"trying to auto create mapping, but dynamic mapping is disabled"}}}}}`

I have tried to enable index.mapper.dynamyc adding a rule in my `elasticsearch.yml`. But it returns to me an error if I type `sudo service elasticsearch status`:

```
    In order to upgrade all indices the settings must be updated via the 
    /${index}/_settings API. Unless all settings are dynamic all indices must be closed 
    in order to apply the upgradeIndices created in the future should use index templates 
    to set default values.

```

So I have tried to enable that parameter via api request:

```
PUT _settings
{
  "index.mapper.dynamic": true
}

```

and creating a new template on elastic, sending this json to the api endpoint:

```
PUT _template/template_2
{
    "template": "my_index",
    "settings": {"index.refresh_interval": "-1"},
    "mappings": {
        "_default_": {
            "_all": {"enabled": false},
            "date_detection": false,
            "dynamic_templates": [
                {"string_fields": {
                    "match": "*",
                    "match_mapping_type": "string",
                    "mapping": {"type": "keyword"}
                }}
            ],
            "properties": {
                "@timestamp": {"type": "date", "format": "dateOptionalTime"},
                "agent": {"type": "text", "fields": {"raw": {"type": "keyword"}}},
                "referrer": {"type": "text", "fields": {"raw": {"type": "keyword"}}},
                "request": {"type": "text", "fields": {"raw": {"type": "keyword"}}},
                "host": {"type": "keyword"},
                "httpversion": {"type": "keyword"},
                "bytes": {"type": "long"},
                "response": {"type": "short"},
                "clientip": {"type": "ip"},
                "geoip": {
                    "type": "object", "dynamic": true,
                    "properties": {"location": {"type": "geo_point"}}
                }
            }
        }
    }
}

```

But I can't resolve my error. What can I try?  
Thanks in advance

---

<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 29, 2018, 1:18pm UTC](https://discuss.elastic.co/t/can-t-create-a-new-index-in-elasticsearch/122064/2 "2018-03-29T13:18:18Z")

</div>

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