From 62959e5c3b4a5019ef964cf7d27c43437d99aff8 Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 4 Nov 2020 14:45:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E9=87=8A=E6=94=BE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 3 ++- .../db/es/fun/ElasticsearchDataModel.java | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/plugin.xml b/plugin.xml index 8dde8ec..f047e1f 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,12 +3,13 @@ com.fr.plugin.db.es.v10 yes - 2.0.0 + 2.0.1 10.0 2019-10-25 fanruan.richie [2020-11-03]支持通过https协议连接服务器。
[2020-09-09]查询语句中可以使用函数拼接。
[2020-03-18]默认使用$..*查询语句获取所有值。
diff --git a/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java b/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java index 2a12f5c..cf1ff27 100644 --- a/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java +++ b/src/main/java/com/fr/plugin/db/es/fun/ElasticsearchDataModel.java @@ -2,10 +2,10 @@ package com.fr.plugin.db.es.fun; import com.fanruan.api.data.open.BaseDataModel; import com.fanruan.api.err.TableDataException; +import com.fanruan.api.log.LogKit; import com.fanruan.api.util.StringKit; import com.fr.json.JSON; import com.fr.json.JSONFactory; -import com.fr.json.JSONObject; import com.fr.plugin.db.es.fun.assist.SimpleDataModel; import com.fr.plugin.db.es.fun.category.ResultStandardizeSelector; import com.fr.plugin.db.es.fun.type.ConverterType; @@ -16,6 +16,7 @@ import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.client.RestClient; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; @@ -68,6 +69,15 @@ public class ElasticsearchDataModel extends BaseDataModel { initData(); } catch (Exception e) { throw new TableDataException(e.getMessage(), e); + } finally { + if (client != null) { + try { + client.close(); + } catch (IOException e) { + LogKit.error(e.getMessage(), e); + } + client = null; + } } } } @@ -132,9 +142,6 @@ public class ElasticsearchDataModel extends BaseDataModel { @Override public void release() throws Exception { - if (client != null) { - client.close(); - client = null; - } + } }