Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:update es query field #577

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions jcommon/docean-plugin/docean-plugin-es-antlr4/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
支持大多数kibana语法,只需要写语法即可生成SearchRequest去查询,具体可当单元测试
支持大多数kibana语法,只需要写语法即可生成SearchRequest去查询,具体可看单元测试

支持多种语法,使用括号可以支持优先级
需要需要新加语法或者减少语法,可以直接修改g4包下[EsQuery.g4]文件,然后在idea中
右击 Generate Antlr Recongnizer重新生成生成语法类(在query包下)
直接使用[EsQueryUtils.java]使用
直接使用[EsQueryUtils.java]使用

表达式一: 变量 运算符 值
变量: 非数字开头的数字、字母、下划线组合
运算符:

":" :等于
"!=" :不等于
">" :大于
"<" :小于
"<=" :小于等于
">=" :大于等于
"=~" : 正则
"!~" : 正则取反
"IN" :包含在
"NOT_IN" :不包含在
"CONTAINS"
"NOTCONTAINS"

a>=2022-07-11 16:00:00.000 AND b<=2022-07-11 17:00:00.000
包含关系 name IN ["张三","李四","王五"]

":" "!=" ">" "<" "<=" ">=" "IN" "NOT_IN" "EXIST" "NOT_EXIST" 以及逻辑AND OR NOT

聚合效果后期支持
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum ValueTypeEnum {
NULL("null", "NULL"),
ARRAY("array", "ARRAY"),
EQUAL(":", "equal"),
IDENTIFY("identifier", "identifier"),
REGEX("regex", "REGEX");

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ public void exitIdentifierValue(EsQueryParser.IdentifierValueContext ctx) {
if (ctx.getParent() instanceof EsQueryParser.EqExprContext) {
//属于等于下的值
valueProperty.put(ctx, new ValueContext(ValueTypeEnum.EQUAL, ctx.getChild(0).getText()));
} else if (ctx.getParent() instanceof EsQueryParser.NeExprContext) {
valueProperty.put(ctx, new ValueContext(ValueTypeEnum.IDENTIFY, ctx.getChild(0).getText()));
} else if (ctx.getParent() instanceof EsQueryParser.ArrayContext) {
valueProperty.put(ctx, new ValueContext(ValueTypeEnum.STRING, ctx.getChild(0).getText()));
} else {
String value = ctx.getChild(0).getText();
if (null == value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void init() {

@After
public void end() {
if(null != searchResponse){
if (null != searchResponse) {
SearchHit[] hits = searchResponse.getHits().getHits();
if (hits == null || hits.length == 0) {
return;
Expand Down Expand Up @@ -145,16 +145,37 @@ public void test10() throws IOException {
}

@Test
public void test11(){
public void test11() {
String str = " (not http) and 8088";
String esQuery = EsQueryUtils.getEsQuery(str);
System.out.println(esQuery);
}

@Test
public void test12(){
public void test12() {
String str = "10.38.201.233";
String esQuery = EsQueryUtils.getEsQuery(str);
System.out.println(esQuery);
}

/**
* 某个key的值不等于value
*/
@Test
public void test13(){
// String str = "level != INFO";
String str = "level != \"INFO\"";
String esQuery = EsQueryUtils.getEsQuery(str);
System.out.println(esQuery);
}
@Test
public void test14(){
// String str = "linenumber< 128";
// String str = "level in [\"ERROR\",\"INFO\"]";
String str = "level in [ERROR,INFO]";
String esQuery = EsQueryUtils.getEsQuery(str);
System.out.println(esQuery);
}


}