在已存在的索引mapping中添加字段,基于es7.17.6
java代码如下
private static void putMapping() {
try {
// 创建PutMappingRequest对象
PutMappingRequest request = new PutMappingRequest(indexName);
// 定义字段的映射
String mappingJson = "{" +
" \"properties\":{" +
" \"field_name\": {" +
" \"type\": \"keyword\"" +
" }" +
" }"
// 将JSON字符串添加到请求中
request.source(mappingJson, XContentType.JSON);
// 发送请求更新映射
client.indices().putMapping(request, RequestOptions.DEFAULT);
System.out.println("Mapping updated successfully");