10
votes

I am getting a warning:

"[types removal] Specifying types in bulk requests is deprecated."]

What do I do wrong? This is my code:

    BulkRequest request = new BulkRequest();

    for(Item item : items) {
        IndexRequest indexRequest = new IndexRequest(INDEX_NAME, DOC_TYPE, item.getIdentifier());
        indexRequest
                .opType(DocWriteRequest.OpType.INDEX) // Index the source. If there an existing document with the id, it will be replaced.
                .source(JsonUtility.toJson(item), XContentType.JSON);

        request.add(indexRequest);
    }

    elastic.bulk(request, RequestOptions.DEFAULT);
2
you are probably using ES 7.0 or newer. Check the version you haveJBone
@JBone ,I got the same warning message and I'm using the version 7.4.0 with spring boot, how can I fix this problem?,what I shoud do?.Ghiloufi
This stackoverflow.com/questions/62322613/… could also lead to the message and is very difficult to spot. Basically - if you misspell an endpoint you can get this error message. Not sure if it could happen with ES higher level clients, but it's worth mentioning it as it took like an hour to realize.Pavel Donchev

2 Answers

7
votes

The mapping type was removed in Elasticsearch 8 and is deprecated in Elasticsearch 7.

No Elasticsearch version is mentioned in your question, but you can read more about the schedule for removal of mapping types, and react accordingly.

0
votes

I think you are working with a 7.X version and the problem is you create the IndexRequest are constructing the URL of the POST method to search in ElasticSearch, something close to:

  • http://localhost:9200/INDEX_NAME_identifier/DOC_TYPE/_search

Where identifier is the attribute used to discriminate in the search. In ElasticSearch 7 specifying types in search requests were deprecated and the URL should be something close to:

  • http://localhost:9200/INDEX_NAME_identifier/_search

Although it is hard to know because you don't specify the versions, I think the elasticsearch library in your code is older than 7.X, if you updated it to 7 probably the DOC_TYPE param disappears in the constructor.