禁用索引 ElasticSeacrh 中类型为“object”的索引参数

问题描述 投票:0回答:1

我使用 ElasticSearch 8.6.2 存储自定义日志,我构建一个 Java 对象并使用 RestHighLevelClient 将其保存到 ELC。我在ELK保存的类:

public class DetailedLogModel {

    private Map<String, Object> variables;
    private String accountId;
    private String event;
    private String trackId;
    private String requestId;
    private String processInstanceId;
    private String contextPath;
    private String confId;
    private LocalDateTime dateTime;
    private String componentId;
    private String componentName;
    private String parentActionId;
    private String parentProcessInstanceId;
    private String actionId;
    private ActionDetailLogType actionType;
    private String uri;
    private String method;

我对除“变量”之外的所有字段的自动索引感到满意,因为它可以存储无限数量的其他字段,这是一个问题,我该如何解决?一切都会有所帮助,甚至是指定主体的 REST 请求的示例。 我尝试了使用此配置创建索引的选项

{
  "mappings": {
    "properties": {
      "variables": {
        "type": "object",
        "index": false, 
        "store": true     
      }
    
    }
  }
}

但是我有错误

{
    "error": {
        "root_cause": [
            {
                "type": "mapper_parsing_exception",
                "reason": "Mapping definition for [variables] has unsupported parameters:  [index : false] [store : true]"
            }
        ],
        "type": "mapper_parsing_exception",
        "reason": "Failed to parse mapping: Mapping definition for [variables] has unsupported parameters:  [index : false] [store : true]",
        "caused_by": {
            "type": "mapper_parsing_exception",
            "reason": "Mapping definition for [variables] has unsupported parameters:  [index : false] [store : true]"
        }
    },
    "status": 400
}

它仅适用于具有关键字和文本类型的字段。也许有人会告诉你如何查看索引字段列表?我正在使用 GET http://127.0.0.1:9200/detail_log_2023-11-23/_mapping 。但这并不能反映现实,因为变量字段无论如何都会被索引。

elasticsearch elastic-stack spring-data-elasticsearch elk
1个回答
0
投票

您需要使用特定于对象字段的

enabled
映射参数

{
  "mappings": {
    "properties": {
      "variables": {
        "type": "object",
        "enabled": false  
      }
    
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.