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.

Justin
  • 4,461
  • 22
  • 87
  • 152
  • Does the `posts` index/type exist in your cluster? – hudsonb May 03 '19 at 16:10
  • yes it does. i create the post index explicitly just before I attempt the bulk operation – Justin May 03 '19 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](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_schedule_for_removal_of_mapping_types) – Polynomial Proton May 03 '19 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? – kielni May 21 '19 at 14:23
  • @kielni Yeah it is version 7.x (.2 actually) and the corresponding Java libs are the same. – Justin Aug 21 '19 at 17:59
  • @PolynomialProton the default (only type now) _doc type is there. It is the only type supported and is the default in version 7 ( I believe since 6? ). I did verify it didn't somehow get removed/disassociated. – Justin Aug 21 '19 at 18:01
  • @kielni Thank you for the answer, I was facing the same issue but solved it by changing the client version. – KKK Nov 26 '19 at 15:07

1 Answers1

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.