Validation failed because of missing type with hl rest client bulk API

hello :
this is my code:

    BulkRequest request = new BulkRequest();
    for (DataInfo dataInfo : dataInfos) {
        String index = getCurrentIndex(dataInfo.getIndexPrefix());
        String id = dataInfo.getId();
        IndexRequest indexRequest = new IndexRequest(index).id(id).opType(DocWriteRequest.OpType.CREATE);
        String source = GsonEntityMapper.mapToString(dataInfo.getData());
        indexRequest.source(source, XContentType.JSON);
        request.add(indexRequest);
    }
    client.bulk(request, RequestOptions.DEFAULT);

The return value is ‘ type is missing ’ when I execute it;

i want know what‘s the problem whit the code

1 Like

Hi @zhaozeyang,

which version of ES and the high level rest client are you using? If before 7, you need to specify a type for your index request too. To avoid changing this later on, I recommend using the type '_doc'. See: https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0 for more info on types removal.

The version of client is 7.3.0 ; The version of es is 6.8.0
Is the es version is too low?

Hi @zhaozeyang,

It is not recommended to use such a combination, see: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.3/java-rest-high-compatibility.html

But I think the problem would be solved by specifying the type in the request, also with the current combination of client and ES.

1 Like

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