This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 760a17fb45 fix(logging): declare Elasticsearch log field mappings 
(#7261)
760a17fb45 is described below

commit 760a17fb45b1c4200f5666082bf8c6e3d3080b5c
Author: Liming Deng <[email protected]>
AuthorDate: Thu Oct 1 06:28:11 2026 +0800

    fix(logging): declare Elasticsearch log field mappings (#7261)
---
 .../client/ElasticSearchLogCollectClient.java      |  7 ++-
 .../client/ElasticSearchLogMappingTest.java        | 65 ++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClient.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClient.java
index ffd41861f9..5a438e4eac 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClient.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClient.java
@@ -150,7 +150,12 @@ public class ElasticSearchLogCollectClient extends 
AbstractLogConsumeClient<Elas
      */
     public void createIndex(final String indexName) {
         try {
-            client.indices().create(c -> c.index(indexName));
+            client.indices().create(c -> c.index(indexName).mappings(mapping 
-> mapping
+                    // Desensitized values remain in _source without rejecting 
the entire log document.
+                    .properties("timeLocal", property -> property.date(date -> 
date.format("yyyy-MM-dd HH:mm:ss.SSS").ignoreMalformed(true)))
+                    .properties("responseContentLength", property -> 
property.integer(number -> number.ignoreMalformed(true)))
+                    .properties("status", property -> property.integer(number 
-> number.ignoreMalformed(true)))
+                    .properties("upstreamResponseTime", property -> 
property.long_(number -> number.ignoreMalformed(true)))));
         } catch (IOException e) {
             LogUtils.error(LOG, "create index error:", e);
         }
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/test/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogMappingTest.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/test/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogMappingTest.java
new file mode 100644
index 0000000000..67cb30e17d
--- /dev/null
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/test/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogMappingTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.shenyu.plugin.logging.elasticsearch.client;
+
+import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.elasticsearch.indices.CreateIndexRequest;
+import co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient;
+import co.elastic.clients.util.ObjectBuilder;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.function.Function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class ElasticSearchLogMappingTest {
+
+    @Test
+    void createsDailyIndicesWithExplicitLogFieldTypes() throws Exception {
+        ElasticsearchClient client = mock(ElasticsearchClient.class);
+        ElasticsearchIndicesClient indices = 
mock(ElasticsearchIndicesClient.class);
+        when(client.indices()).thenReturn(indices);
+        doAnswer(invocation -> {
+            Function<CreateIndexRequest.Builder, 
ObjectBuilder<CreateIndexRequest>> factory = invocation.getArgument(0);
+            CreateIndexRequest request = factory.apply(new 
CreateIndexRequest.Builder()).build();
+            assertEquals("logs-2026-09-25", request.index());
+            
assertTrue(request.mappings().properties().get("timeLocal").isDate());
+            assertEquals("yyyy-MM-dd HH:mm:ss.SSS", 
request.mappings().properties().get("timeLocal").date().format());
+            
assertTrue(request.mappings().properties().get("responseContentLength").isInteger());
+            
assertTrue(request.mappings().properties().get("status").isInteger());
+            
assertTrue(request.mappings().properties().get("upstreamResponseTime").isLong());
+            assertEquals(Boolean.TRUE, 
request.mappings().properties().get("timeLocal").date().ignoreMalformed());
+            assertEquals(Boolean.TRUE, 
request.mappings().properties().get("responseContentLength").integer().ignoreMalformed());
+            assertEquals(Boolean.TRUE, 
request.mappings().properties().get("status").integer().ignoreMalformed());
+            assertEquals(Boolean.TRUE, 
request.mappings().properties().get("upstreamResponseTime").long_().ignoreMalformed());
+            return null;
+        }).when(indices).create(any(Function.class));
+        ElasticSearchLogCollectClient collector = new 
ElasticSearchLogCollectClient();
+        ReflectionTestUtils.setField(collector, "client", client);
+        collector.createIndex("logs-2026-09-25");
+        verify(indices).create(any(Function.class));
+    }
+}

Reply via email to