0

我正在使用弹性 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 和源。

4

1 回答 1

2

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

请注意,我没有使用客户端的typeand idinCreateIndexRequest方法resthighlevel

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

请参阅删除类型以获取更多信息。

于 2020-04-13T15:06:05.663 回答