我现在使用的是elasctic 6.3.2中的IndexRequest,现在我更改为7.6.2版,如何使用CreateIndexRequest在以下步骤中执行相同的操作。
弹性休息高级客户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客户端有效。
请注意,我没有在type
客户端的id
方法中使用CreateIndexRequest
和resthighlevel
。
String indexString = jsonUtil.getStringFromFile(indexName + ".mapping");
CreateIndexRequest request = new CreateIndexRequest(indexName);
request.source(indexString, XContentType.JSON);
client.indices().create(request, RequestOptions.DEFAULT);