如何在创建索引请求中创建索引类型和 ID?

How to create index type and id in create index request?

我正在使用 elastic 6.3.2 的 IndexRequest。现在我换到了7.6.2版本。我如何使用 CreateIndexRequest 执行以下相同的步骤?

Elastic rest高级客户端6.3.2代码:

 public Object createIndex(Object document, String id) throws IOException {

        Map documentMapper = objectMapper.convertValue(document, Map.class);

        IndexRequest indexRequest = new IndexRequest(this.getIndexName(),
                type, id).source(documentMapper, XContentType.JSON);

        IndexResponse indexResponse = client.index(indexRequest);
        return null;
    }

切换到 7.6.2 后,我无法在 CreateIndexRequest 中创建类型、id 和源。

类型在 Elasticsearch 7.X 中已被弃用,下面是代码,它适用于我使用 resthighlevel 客户端。

请注意,我没有在 resthighlevel 客户端的 CreateIndexRequest 方法中使用 typeid

String indexString = jsonUtil.getStringFromFile(indexName + ".mapping");
CreateIndexRequest request = new CreateIndexRequest(indexName);
request.source(indexString, XContentType.JSON);
client.indices().create(request, RequestOptions.DEFAULT);

请参阅removal of types了解更多信息。