Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
easy-es
easy-es
提交
7c639bfe
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 搜索 >>
提交
7c639bfe
编写于
3月 25, 2022
作者:
FelixHPP
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复DSL查询错误BUG
上级
6db3fbbb
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
74 addition
and
23 deletion
+74
-23
easy-es-core/README.md
easy-es-core/README.md
+0
-0
easy-es-core/src/main/java/indi/felix/easy/core/elastic/model/ElasticFieldValid.java
...indi/felix/easy/core/elastic/model/ElasticFieldValid.java
+3
-0
easy-es-core/src/main/java/indi/felix/easy/core/elastic/model/SettingModel.java
...java/indi/felix/easy/core/elastic/model/SettingModel.java
+10
-7
easy-es-core/src/main/java/indi/felix/easy/core/elastic/rest/EasyRest.java
...main/java/indi/felix/easy/core/elastic/rest/EasyRest.java
+10
-10
easy-es-core/src/main/java/indi/felix/easy/core/elastic/rest/IndexRestApi.java
.../java/indi/felix/easy/core/elastic/rest/IndexRestApi.java
+39
-6
easy-es-core/src/main/java/indi/felix/easy/core/enums/EndpointType.java
...rc/main/java/indi/felix/easy/core/enums/EndpointType.java
+4
-0
easy-es-core/src/test/java/indi/felix/easy/core/elastic/rest/EasyRestTest.java
.../java/indi/felix/easy/core/elastic/rest/EasyRestTest.java
+8
-0
未找到文件。
easy-es-core/README.md
0 → 100644
浏览文件 @
7c639bfe
easy-es-core/src/main/java/indi/felix/easy/core/elastic/model/ElasticFieldValid.java
浏览文件 @
7c639bfe
...
...
@@ -3,6 +3,9 @@ package indi.felix.easy.core.elastic.model;
import
indi.felix.easy.core.elastic.model.metadata.*
;
import
org.apache.commons.lang3.StringUtils
;
/**
* ES 字段验证, 防止把日期类型字段、数值类型字段等设置了分词
*/
public
class
ElasticFieldValid
{
/**
* keyword 类型字段后缀集合
...
...
easy-es-core/src/main/java/indi/felix/easy/core/elastic/model/SettingModel.java
浏览文件 @
7c639bfe
...
...
@@ -22,7 +22,7 @@ public class SettingModel {
private
int
shards
;
/**
* 副本数, 默认
1
, dynamic
* 副本数, 默认
0
, dynamic
*/
private
int
replicas
;
...
...
@@ -38,13 +38,16 @@ public class SettingModel {
*/
private
int
max_result_window
;
/**
* 设置ES 字段最大上限数量
*/
private
int
totalFields
;
public
SettingModel
()
{
this
.
shards
=
1
;
this
.
replicas
=
0
;
this
.
totalFields
=
5000
;
// this.refreshInterval = 1s
this
.
refreshInterval
=
1
;
this
.
max_result_window
=
10000
;
}
...
...
@@ -52,23 +55,23 @@ public class SettingModel {
Map
<
String
,
Object
>
setting
=
new
HashMap
<>();
if
(
shards
>=
0
)
{
setting
.
put
(
"number_of_shards"
,
shards
);
setting
.
put
(
ElasticConstant
.
INDEX_NUMBER_OF_SHARDS
,
shards
);
}
if
(
replicas
>=
0
)
{
setting
.
put
(
"number_of_replicas"
,
replicas
);
setting
.
put
(
ElasticConstant
.
INDEX_NUMBER_OF_REPLICA
,
replicas
);
}
if
(
refreshInterval
>=
0
)
{
setting
.
put
(
"index.refresh_interval"
,
refreshInterval
);
setting
.
put
(
ElasticConstant
.
INDEX_REFRESH_INTERVAL
,
refreshInterval
+
"s"
);
}
if
(
totalFields
>=
0
)
{
setting
.
put
(
"index.mapping.total_fields.limit"
,
totalFields
);
setting
.
put
(
ElasticConstant
.
INDEX_MAPPING_TOTAL_FIELDS_LIMIT
,
totalFields
);
}
if
(
max_result_window
>=
0
)
{
setting
.
put
(
"index.max_result_window"
,
max_result_window
);
setting
.
put
(
ElasticConstant
.
INDEX_MAX_RESULT_WINDOW
,
max_result_window
);
}
return
setting
;
...
...
easy-es-core/src/main/java/indi/felix/easy/core/elastic/rest/EasyRest.java
浏览文件 @
7c639bfe
...
...
@@ -224,7 +224,7 @@ public class EasyRest extends BaseRest {
* @param properties
* @return
*/
public
boolean
createIndex
(
String
index
,
SettingModel
settings
,
MappingModel
properties
)
{
public
boolean
createIndex
ByModel
(
String
index
,
SettingModel
settings
,
MappingModel
properties
)
{
Map
<
String
,
Object
>
mapping
=
new
HashMap
<>();
Map
<
String
,
Object
>
setting
=
new
HashMap
<>();
...
...
@@ -276,7 +276,7 @@ public class EasyRest extends BaseRest {
String
routing
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
DSLEnum
dslEnum
=
DSLEnum
.
getByQuery
(
method
,
endpointType
.
n
ame
());
DSLEnum
dslEnum
=
DSLEnum
.
getByQuery
(
method
,
endpointType
.
getN
ame
());
if
(
dslEnum
==
null
)
{
msg
=
"不支持"
+
method
+
"和"
+
dslEnum
+
"的组合类型,请重新选择."
;
map
.
put
(
"status"
,
false
);
...
...
@@ -285,25 +285,25 @@ public class EasyRest extends BaseRest {
}
switch
(
dslEnum
)
{
case
DSL_GET_SEARCH:
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
n
ame
()
+
"?format=json&pretty"
;
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
getN
ame
()
+
"?format=json&pretty"
;
break
;
case
DSL_GET_COUNT:
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
n
ame
();
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
getN
ame
();
break
;
case
DSL_GET_MAPPING:
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
n
ame
()
+
"?format=json&pretty"
;
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
getN
ame
()
+
"?format=json&pretty"
;
break
;
case
DSL_PUT_MAPPING:
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
n
ame
();
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
getN
ame
();
break
;
case
DSL_GET_SETTINGS:
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
n
ame
()
+
"?format=json&pretty"
;
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
getN
ame
()
+
"?format=json&pretty"
;
break
;
case
DSL_PUT_SETTINGS:
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
n
ame
();
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
getN
ame
();
break
;
case
DSL_POST_ANALYZE:
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
n
ame
()
+
"?format=json&pretty"
;
endpoint
=
"/"
+
dslIndex
+
"/"
+
endpointType
.
getN
ame
()
+
"?format=json&pretty"
;
break
;
case
DSL_DELETE_BY_ID:
case
DSL_UPDATE_BY_ID:
...
...
@@ -326,7 +326,7 @@ public class EasyRest extends BaseRest {
break
;
default
:
ret
=
false
;
msg
=
"不支持"
+
method
+
"和"
+
endpointType
.
n
ame
()
+
"的组合类型,请重新选择."
;
msg
=
"不支持"
+
method
+
"和"
+
endpointType
.
getN
ame
()
+
"的组合类型,请重新选择."
;
break
;
}
...
...
easy-es-core/src/main/java/indi/felix/easy/core/elastic/rest/IndexRestApi.java
浏览文件 @
7c639bfe
...
...
@@ -2,6 +2,7 @@ package indi.felix.easy.core.elastic.rest;
import
indi.felix.easy.core.elastic.client.XContentUtils
;
import
indi.felix.easy.core.elastic.model.ESFieldTypeEnum
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.entity.ContentType
;
import
org.apache.http.nio.entity.NStringEntity
;
...
...
@@ -60,22 +61,47 @@ public class IndexRestApi extends BaseRest {
return
responseBody
(
defaultMethod
,
index
);
}
/**
* curl -XGET 'localhost:9200/_
mapping
* curl -XGET 'localhost:9200/_
settings
*
* @return 多个索引用英文逗号分隔
*/
public
String
getMapping
()
{
public
String
getSetting
()
{
return
getSetting
(
null
);
}
/**
* curl -XGET 'localhost:9200/_settings
*
* @return 多个索引用英文逗号分隔
*/
public
String
getSetting
(
String
index
)
{
String
newEndpoint
=
""
;
if
(
StringUtils
.
isNotBlank
(
index
))
{
index
=
index
+
"/"
;
}
else
{
index
=
""
;
}
if
(!
isAllowIncludeType
())
{
newEndpoint
=
"_mapping
"
;
newEndpoint
=
index
+
"_settings
"
;
}
else
{
// 6.x版本无法识别include_type_name参数
newEndpoint
=
"_mapping
?include_type_name=true"
;
newEndpoint
=
index
+
"_settings
?include_type_name=true"
;
}
return
responseBody
(
defaultMethod
,
newEndpoint
);
}
/**
* curl -XGET 'localhost:9200/_mapping
*
* @return 多个索引用英文逗号分隔
*/
public
String
getMapping
()
{
return
getMapping
(
null
);
}
/**
* curl -XGET 'localhost:9200/twitter/_mapping
...
...
@@ -84,11 +110,18 @@ public class IndexRestApi extends BaseRest {
*/
public
String
getMapping
(
String
index
)
{
String
newEndpoint
=
""
;
if
(
StringUtils
.
isNotBlank
(
index
))
{
index
=
index
+
"/"
;
}
else
{
index
=
""
;
}
if
(!
isAllowIncludeType
())
{
newEndpoint
=
index
+
"
/
_mapping"
;
newEndpoint
=
index
+
"_mapping"
;
}
else
{
// 6.x版本无法识别include_type_name参数
newEndpoint
=
index
+
"
/
_mapping?include_type_name=true"
;
newEndpoint
=
index
+
"_mapping?include_type_name=true"
;
}
return
responseBody
(
defaultMethod
,
newEndpoint
);
...
...
easy-es-core/src/main/java/indi/felix/easy/core/enums/EndpointType.java
浏览文件 @
7c639bfe
...
...
@@ -17,4 +17,8 @@ public enum EndpointType {
this
.
type
=
type
;
this
.
name
=
name
;
}
public
String
getName
(){
return
name
;
}
}
easy-es-core/src/test/java/indi/felix/easy/core/elastic/rest/EasyRestTest.java
浏览文件 @
7c639bfe
...
...
@@ -142,6 +142,14 @@ public class EasyRestTest extends TestCase {
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
String
indexName2
=
"test000231"
;
Assert
.
assertTrue
(
easyEs
.
rest
().
createIndex
(
indexName2
,
null
,
null
));
Assert
.
assertTrue
(
easyEs
.
rest
().
indexExists
(
indexName2
));
System
.
out
.
println
(
easyEs
.
rest
().
index
().
getMapping
(
indexName2
));
System
.
out
.
println
(
easyEs
.
rest
().
index
().
getSetting
(
indexName2
));
Assert
.
assertTrue
(
easyEs
.
rest
().
deleteIndex
(
indexName2
));
}
public
void
testMain
(){
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录