3

Java 1.8, Elasticsearch Low and High Level Rest Clients 7.0.0

I am trying the simple example from the docs found here: Bulk API

BulkRequest bulkRequest = new BulkRequest();
request.add(new IndexRequest("posts").id("1")  
    .source(XContentType.JSON,"field", "valueString"));
 // not working


Map<String, Object> doc1 = new HashMap<>();
doc1.put("property", "value");
request.add(new IndexRequest("posts").id("1").source(doc1);
 // this is easy to add as a single IndexRequest, but not working here

 BulkResponse bulkResponse = this.getClient().bulk(request, RequestOptions.DEFAULT);
 // this is the line throwing the error, straight from the docs

error:

{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: type is missing;"}],"type":"action_request_validation_exception","reason":"Validation Failed: 1: type is missing;"},"status":400}
        at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:260)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:238)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:212)
        at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1433)
        ... 6 more

so what type is missing? I have tried adding mappings, add opType("create") to the IndexRequest that is created inside the request.add()?

Yeah this is probably some simple oversight on my part but I have been wrestling this for a while guys and would appreciate some help.

7
  • Does the posts index/type exist in your cluster? Commented May 3, 2019 at 16:10
  • yes it does. i create the post index explicitly just before I attempt the bulk operation Commented May 3, 2019 at 16:57
  • How does your index mapping look like? This looks like a missing doc type in the index. May be try using _doc as type. From 7.0 types were removed Commented May 3, 2019 at 17:29
  • 4
    I saw this error when I was trying to use the 7.0 client to index against a 6.x server; can you verify your server version is 7.x? Commented May 21, 2019 at 14:23
  • @kielni Yeah it is version 7.x (.2 actually) and the corresponding Java libs are the same. Commented Aug 21, 2019 at 17:59

1 Answer 1

2

"missing type" arises because of missing "_doc" in your request. Changing new IndexRequest("posts") to new IndexRequest("posts","_doc") might work. This will give a 'deprecated' warning since _types are removed in Elastic 7.x.x.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.