user3489820
user3489820

Reputation: 1519

ElasticSearch: Specifying types in bulk requests is deprecated

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);

Upvotes: 10

Views: 28103

Answers (2)

egarcia
egarcia

Reputation: 21

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.

Upvotes: 0

ch33hau
ch33hau

Reputation: 2951

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.

Upvotes: 8

Related Questions