Хочу создать документ, где поле request и response может принимать любой тип (Object, String, Integer, null)
но при маппинге ругается:
: Elasticsearch exception [type=illegal_argument_exception, reason=Can't merge a non object mapping [request] with an object mapping [request]]
Вопрос, как можно это реализовать?
Код:
@Data
@Accessors(chain = true)
@Document(indexName = "backoffice-action")
public class ExtendedBackofficeActionEntity {
@Id
private String id;
@Field(type = FieldType.Text)
private String serviceName;
@Field(type = FieldType.Text)
private String userName;
@Field(type = FieldType.Keyword)
private String login;
@Field(type = FieldType.Keyword)
private String requestPath;
@Field(type = FieldType.Keyword)
private String requestMethod;
@Field(type = FieldType.Text)
private String queryParams;
@Field(type = FieldType.Keyword)
private String requestId;
@Field(type = FieldType.Object)
private Object request;
@Field(type = FieldType.Object)
private Object response;
@Field(type = FieldType.Date, name = "@timestamp")
private Instant requestedAt;
@Field(type = FieldType.Integer)
private Integer responseStatus;
@Transient
private boolean isValid;
}
@PostConstruct
public void configureIndices() {
var indexName = logProperties.getIndex().getExtendedBackofficeAction();
if (!elasticsearchOperations.indexExists(indexName)) {
createIndex(indexName);
}
}
private void createIndex(String indexName){
var settings = new HashMap<String, Object>();
settings.put(INDEX_NUMBER_OF_SHARDS, logProperties.getExtendedBackofficeActionShards());
settings.put(INDEX_NUMBER_OF_REPLICAS, logProperties.getExtendedBackofficeActionReplicas());
elasticsearchOperations.createIndex(indexName, settings);
elasticsearchOperations.putMapping(ExtendedBackofficeActionEntity.class, getDynamicTemplateMapping());
}
// Create dynamic type template for request and response fields (ExtendedBackofficeActionEntity)
private Map<String, Object> getDynamicTemplateMapping() {
Map<String, Object> dynamicTemplate = new HashMap<>();
dynamicTemplate.put("dynamic_templates", List.of(
Map.of(
"request_response_fields", Map.of(
"path_match", "request|response",
"mapping", Map.of(
"type", "object",
"dynamic", true
)
)
)
));
return dynamicTemplate;
}
P.s Elastic version: 6.8.16