Hi,
What version are you running this test against? I tried the same, below, and ended up with data in a local elasticsearch cluster. I am running from a build of our code in the master branch.
public static void main(String[] args) throws IOException {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("localhost", 9200, "http")));
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
{
builder.field("user", "kimchy");
builder.timeField("postDate", new java.util.Date());
builder.field("message", "trying out Elasticsearch");
}
builder.endObject();
IndexRequest indexRequest = new IndexRequest("posts", "doc", "1")
.source(builder);
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
}
yields
% curl localhost:9200/posts/doc/1
{"_index":"posts","_type":"doc","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{"user":"kimchy","postDate":"2019-02-27T18:44:30.669Z","message":"trying out Elasticsearch"}}%
and generates one warning due to types removal (the docs are different in 7.0 but i wanted to use the docs you linked to ensure i got the correct data.
[2019-02-27T12:44:30,892][WARN ][o.e.c.RestClient ] [[main]] request [PUT http://localhost:9200/posts/doc/1?timeout=1m] returned 1 warnings: [299 Elasticsearch-8.0.0-SNAPSHOT-bc60ca8 "[types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id})."]
and a call to verify the mapping
% curl localhost:9200/posts/_mapping
{"posts":{"mappings":{"properties":{"message":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"postDate":{"type":"date"},"user":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}}%
Can you post a full snippet that shows the failure and tell me the version you are using as well?