Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
easy-es
easy-es
提交
b9e75ea6
E
easy-es
项目概览
easy-es
/
easy-es
通知
96
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
easy-es
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b9e75ea6
编写于
12月 16, 2021
作者:
W
wangpenghui
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://codechina.csdn.net/easy-es/easy-es
上级
3e5d9449
7d936eb4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
110 addition
and
1 deletion
+110
-1
easy-es-core/pom.xml
easy-es-core/pom.xml
+14
-0
easy-es-core/src/main/java/indi/felix/easy/core/elastic/rest/BaseRest.java
...main/java/indi/felix/easy/core/elastic/rest/BaseRest.java
+67
-0
easy-es-core/src/test/java/indi/felix/easy/core/elastic/rest/BaseRestTest.java
.../java/indi/felix/easy/core/elastic/rest/BaseRestTest.java
+13
-0
pom.xml
pom.xml
+16
-1
未找到文件。
easy-es-core/pom.xml
浏览文件 @
b9e75ea6
...
...
@@ -54,6 +54,12 @@
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
<version>
${elasticsearch.version}
</version>
<exclusions>
<exclusion>
<artifactId>
log4j-api
</artifactId>
<groupId>
org.apache.logging.log4j
</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client -->
<dependency>
...
...
@@ -74,11 +80,19 @@
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-core
</artifactId>
<version>
${log4j2.version}
</version>
<exclusions>
<exclusion>
<artifactId>
log4j-api
</artifactId>
<groupId>
org.apache.logging.log4j
</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-api
</artifactId>
<version>
${log4j2.version}
</version>
</dependency>
<dependency>
<groupId>
commons-logging
</groupId>
...
...
easy-es-core/src/main/java/indi/felix/easy/core/elastic/rest/BaseRest.java
浏览文件 @
b9e75ea6
package
indi.felix.easy.core.elastic.rest
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
indi.felix.easy.core.elastic.client.RequestHelper
;
import
indi.felix.easy.core.elastic.utool.Const
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.Header
;
...
...
@@ -29,9 +32,33 @@ public abstract class BaseRest {
public
static
final
String
GET
=
"GET"
,
POST
=
"POST"
,
PUT
=
"PUT"
,
DELETE
=
"DELETE"
,
HEAD
=
"HEAD"
;
public
String
version
;
public
String
defaultDocType
;
protected
BaseRest
(
RestClient
restClient
)
{
this
.
restClient
=
restClient
;
this
.
version
=
getVersion
();
if
(
compareVersion
(
this
.
version
,
"7.0.0"
)
>
0
)
{
// 7.x 版本中_doc 为默认路径
defaultDocType
=
"_doc"
;
}
else
{
defaultDocType
=
Const
.
DOC_TYPE
;
}
}
/**
* 获取ES版本号
*
* @return
*/
public
String
getVersion
()
{
String
json
=
responseBody
(
GET
,
""
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
json
);
JSONObject
versionJson
=
jsonObject
!=
null
?
jsonObject
.
getJSONObject
(
"version"
)
:
null
;
String
version
=
versionJson
!=
null
?
versionJson
.
getString
(
"number"
)
:
null
;
return
version
;
}
public
String
responseBody
(
String
method
,
String
endpoint
)
{
...
...
@@ -130,4 +157,44 @@ public abstract class BaseRest {
return
response
;
}
/**
* 版本号比较
*
* @param v1
* @param v2
* @return 0代表相等,1代表左边大,-1代表右边大
* Utils.compareVersion("1.0.358_20180820090554","1.0.358_20180820090553")=1
*/
public
int
compareVersion
(
String
v1
,
String
v2
)
{
if
(
v1
.
equals
(
v2
))
{
return
0
;
}
String
[]
version1Array
=
v1
.
split
(
"[._]"
);
String
[]
version2Array
=
v2
.
split
(
"[._]"
);
int
index
=
0
;
int
minLen
=
Math
.
min
(
version1Array
.
length
,
version2Array
.
length
);
long
diff
=
0
;
while
(
index
<
minLen
&&
(
diff
=
Long
.
parseLong
(
version1Array
[
index
])
-
Long
.
parseLong
(
version2Array
[
index
]))
==
0
)
{
index
++;
}
if
(
diff
==
0
)
{
for
(
int
i
=
index
;
i
<
version1Array
.
length
;
i
++)
{
if
(
Long
.
parseLong
(
version1Array
[
i
])
>
0
)
{
return
1
;
}
}
for
(
int
i
=
index
;
i
<
version2Array
.
length
;
i
++)
{
if
(
Long
.
parseLong
(
version2Array
[
i
])
>
0
)
{
return
-
1
;
}
}
return
0
;
}
else
{
return
diff
>
0
?
1
:
-
1
;
}
}
}
easy-es-core/src/test/java/indi/felix/easy/core/elastic/rest/BaseRestTest.java
0 → 100644
浏览文件 @
b9e75ea6
package
indi.felix.easy.core.elastic.rest
;
import
indi.felix.easy.core.elastic.EasyEs
;
import
junit.framework.TestCase
;
public
class
BaseRestTest
extends
TestCase
{
public
void
testGetVersion
()
{
EasyEs
es
=
new
EasyEs
(
"localhost:9200"
);
String
version
=
es
.
rest
().
getVersion
();
System
.
out
.
println
(
version
);
}
}
\ No newline at end of file
pom.xml
浏览文件 @
b9e75ea6
...
...
@@ -36,6 +36,7 @@
<commons-dbutils.version>
1.7
</commons-dbutils.version>
<disruptor.version>
3.4.2
</disruptor.version>
<spring-boot.version>
2.4.1
</spring-boot.version>
<log4j2.version>
2.15.0
</log4j2.version>
</properties>
<dependencyManagement>
<dependencies>
...
...
@@ -70,7 +71,21 @@
<version>
${junit.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-core
</artifactId>
<version>
${log4j2.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-api
</artifactId>
<version>
${log4j2.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录