gpt4 book ai didi

elasticsearch - 如何使用REST模板使用JSON文件向Elastic Search发出PUT请求

转载 作者:行者123 更新时间:2023-12-02 22:19:14 24 4
gpt4 key购买 nike

我正在创建一个SpringBoot应用程序,需要在Elastic Search中放置一个JSON模式。 JSON模式将位于我的资源文件夹中(位于我的类路径中)。如何使用REST模板放置原始JSON文件。

“有什么帮助吗?”由于Internet上的大多数示例只是假设我们要发送一个POJO类。但是这里我不了解JSON模式。我需要使用原始JSON文件发出请求。

最佳答案

假设json模式包含索引的映射/设置。然后,您可以如下所示放置映射:

CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(index);
// CREATE MAPPING
String mapping_json = new String(Files.readAllBytes(json_mapping_path));
createIndexRequestBuilder.addMapping("my_mapping", mapping_json);
CreateIndexResponse indexResponse = createIndexRequestBuilder.execute().actionGet();

关于elasticsearch - 如何使用REST模板使用JSON文件向Elastic Search发出PUT请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42898036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com