This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new a793b19ef35 [fix](es) Handle object type in Elasticsearch mapping when
table is empty (#56152)
a793b19ef35 is described below
commit a793b19ef3538001edb6c9cb2a069dc59537e2a3
Author: Socrates <[email protected]>
AuthorDate: Tue Sep 23 04:55:12 2025 +0800
[fix](es) Handle object type in Elasticsearch mapping when table is empty
(#56152)
### What problem does this PR solve?
This PR fixes an issue with Elasticsearch external tables when the table
is empty but contains object type fields. In such cases, the
Elasticsearch mapping still explicitly shows `"type": "object"` for
object fields, but Doris was not handling this type correctly, leading
to type mapping failures.
---
.../elasticsearch/scripts/es_init.sh | 2 ++
.../scripts/index/es7_test_object.json | 16 ++++++++++++++++
.../org/apache/doris/datasource/es/EsUtil.java | 2 ++
.../data/external_table_p0/es/test_es_query.out | Bin 162279 -> 162443 bytes
.../external_table_p0/es/test_es_query.groovy | 2 ++
5 files changed, 22 insertions(+)
diff --git
a/docker/thirdparties/docker-compose/elasticsearch/scripts/es_init.sh
b/docker/thirdparties/docker-compose/elasticsearch/scripts/es_init.sh
index 4a734a504dd..7344dc09a27 100755
--- a/docker/thirdparties/docker-compose/elasticsearch/scripts/es_init.sh
+++ b/docker/thirdparties/docker-compose/elasticsearch/scripts/es_init.sh
@@ -130,6 +130,8 @@ curl "http://${ES_7_HOST}:9200/test2_20220808" -H
"Content-Type:application/json
curl "http://${ES_7_HOST}:9200/test2_20220809" -H
"Content-Type:application/json" -X PUT -d '@/mnt/scripts/index/es7_test2.json'
# create index test3_20231005
curl "http://${ES_7_HOST}:9200/test3_20231005" -H
"Content-Type:application/json" -X PUT -d '@/mnt/scripts/index/es7_test3.json'
+# create index test_object for object type testing (empty table)
+curl "http://${ES_7_HOST}:9200/test_object" -H "Content-Type:application/json"
-X PUT -d '@/mnt/scripts/index/es7_test_object.json'
# put data for tese1
curl "http://${ES_7_HOST}:9200/test1/_doc/1" -H
"Content-Type:application/json" -X POST -d '@/mnt/scripts/data/data1.json'
curl "http://${ES_7_HOST}:9200/test1/_doc/2" -H
"Content-Type:application/json" -X POST -d '@/mnt/scripts/data/data2.json'
diff --git
a/docker/thirdparties/docker-compose/elasticsearch/scripts/index/es7_test_object.json
b/docker/thirdparties/docker-compose/elasticsearch/scripts/index/es7_test_object.json
new file mode 100644
index 00000000000..18405ea38b2
--- /dev/null
+++
b/docker/thirdparties/docker-compose/elasticsearch/scripts/index/es7_test_object.json
@@ -0,0 +1,16 @@
+{
+ "settings": {
+ "number_of_shards": 1,
+ "number_of_replicas": 0
+ },
+ "mappings": {
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "user_info": {
+ "type": "object"
+ }
+ }
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/es/EsUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/es/EsUtil.java
index 55fea86718a..a350f386ada 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/es/EsUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/es/EsUtil.java
@@ -300,6 +300,8 @@ public class EsUtil {
case "constant_keyword":
type = ScalarType.createStringType();
break;
+ // When ES table is empty, object fields still have explicit
"type": "object" in mapping
+ case "object":
case "nested":
type = Type.JSONB;
break;
diff --git a/regression-test/data/external_table_p0/es/test_es_query.out
b/regression-test/data/external_table_p0/es/test_es_query.out
index e517648c949..536d492b64c 100644
Binary files a/regression-test/data/external_table_p0/es/test_es_query.out and
b/regression-test/data/external_table_p0/es/test_es_query.out differ
diff --git a/regression-test/suites/external_table_p0/es/test_es_query.groovy
b/regression-test/suites/external_table_p0/es/test_es_query.groovy
index 22789b9ebe1..4994018a4c0 100644
--- a/regression-test/suites/external_table_p0/es/test_es_query.groovy
+++ b/regression-test/suites/external_table_p0/es/test_es_query.groovy
@@ -344,6 +344,8 @@ suite("test_es_query",
"p0,external,es,external_docker,external_docker_es") {
order_qt_sql_7_36 """select test1, test2 from test1 where test2
like 'text%';"""
order_qt_sql_7_37 """select test9 from test1;"""
order_qt_sql_7_38 """select test9 from test2;"""
+ order_qt_sql_7_39 """desc test_object;"""
+ order_qt_sql_7_40 """select * from test_object;"""
List<List<String>> tables7N = sql """show tables"""
boolean notContainHide7 = true
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]