# ElasticSearch Index Mapping with Java Client

**URL:** <https://discuss.elastic.co/t/elasticsearch-index-mapping-with-java-client/177993>\
**Category:** Elasticsearch\
**Created:** [April 23, 2019, 9:05am UTC](https://discuss.elastic.co/t/elasticsearch-index-mapping-with-java-client/177993 "2019-04-23T09:05:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thebuleon29](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@thebuleon29](https://discuss.elastic.co/u/thebuleon29)\
**Post date:** [April 23, 2019, 9:05am UTC](https://discuss.elastic.co/t/elasticsearch-index-mapping-with-java-client/177993/1 "2019-04-23T09:05:23Z")

</div>

Hi,

I want to use ElasticSearch 6.6 as a Time Series Database and need to map the timestamp as a date to plot the data in Grafana. I am stuck at the index creation because Java keeps throwing the same exception :

`org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: mapping type is missing;`

I tried two different ways to make it working :

1. Importing a JSON from a file :

The JSON file :

```
{
    "properties":{
        "@timestamp":{"type":"date","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "alert":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "curve":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "engValidity":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "engValue":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "limits":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "monState":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "rawValidity":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "sample":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "spid":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "bitOffset":{"type":"float"},
        "bitSize":{"type":"float"},
        "pk":{"type":"float"},
        "rawValue":{"type":"float"},
        "receivedTime":{"type":"float"}
    }
}

```

1. Building the JSON with a HashMap :

I can't find where I did a mistake...

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 23, 2019, 9:28am UTC](https://discuss.elastic.co/t/elasticsearch-index-mapping-with-java-client/177993/2 "2019-04-23T09:28:39Z")

</div>

I think that your JSON file should be like:

```auto
{
  "TYPENAME": {
    "properties":{
        "@timestamp":{"type":"date","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "alert":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "curve":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "engValidity":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "engValue":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "limits":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "monState":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "rawValidity":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "sample":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "spid":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "bitOffset":{"type":"float"},
        "bitSize":{"type":"float"},
        "pk":{"type":"float"},
        "rawValue":{"type":"float"},
        "receivedTime":{"type":"float"}
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![thebuleon29](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@thebuleon29](https://discuss.elastic.co/u/thebuleon29)\
**Post date:** [April 23, 2019, 10:48am UTC](https://discuss.elastic.co/t/elasticsearch-index-mapping-with-java-client/177993/3 "2019-04-23T10:48:20Z")

</div>

It returns the same error 😢

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 26, 2019, 10:12am UTC](https://discuss.elastic.co/t/elasticsearch-index-mapping-with-java-client/177993/4 "2019-04-26T10:12:42Z")

</div>

I tried the following but on a 6.7 version.

```auto
        try (RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(HttpHost.create("http://localhost:9200")))) {
            try {
                client.indices().delete(new DeleteIndexRequest("test"), RequestOptions.DEFAULT);
            } catch (ElasticsearchStatusException ignored) { }
            client.indices().create(new CreateIndexRequest("test"), RequestOptions.DEFAULT);
            PutMappingRequest request =
                    new PutMappingRequest("test").source("{\n" +
                            " \"properties\":{\n" +
                            " \"foo\":{\"type\":\"text\"}\n" +
                            " }\n" +
                            "}", XContentType.JSON);
            client.indices().putMapping(request, RequestOptions.DEFAULT);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }

```

This works well for me. May be that could help?

---

<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:** [May 24, 2019, 10:12am UTC](https://discuss.elastic.co/t/elasticsearch-index-mapping-with-java-client/177993/5 "2019-05-24T10:12:44Z")

</div>

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