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 grammar (ip handle) #580

Merged
merged 2 commits into from
Aug 14, 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
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ NUMBER
;

SEGMENT
: ([0-9] | [1-9][0-9] | '1'[0-9][0-9] | '2'[0-4]'5' | '2'[0-4][0-4] | [1-2]'5'[0-4] )
: ([0-9] | [1-9][0-9] | '1'[0-9][0-9] | '2'[0-4]'5' | '2'[0-4][0-9] | [1-2]'5'[0-4] )
| '*'
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class EsQueryTransfer implements EsQueryListener {

public static final String DOUBLE_QUOTATION_MARK_SEPARATOR = "\"";
public static final String DOUBLE_QUOTATION_MARK_SEPARATOR = "~";

private ParseTreeProperty<SearchSourceBuilder> treeProperty = new ParseTreeProperty<>();

Expand Down Expand Up @@ -91,9 +91,15 @@ public void enterNotExpression(EsQueryParser.NotExpressionContext ctx) {
public void exitNotExpression(EsQueryParser.NotExpressionContext ctx) {
//获取到括号内得表达式
//注:“非”逻辑不论包含多少参数都需加上括号,NOT(a:1)、 NOT(a : 1 AND b : 2)
ParseTree tree = ctx.children.get(1);
SearchSourceBuilder sourceBuilder = MergeUtils.MergeNot(treeProperty.get(tree));
treeProperty.put(ctx, sourceBuilder);
if ("not".equals(ctx.children.get(0).getText()) || "NOT".equals(ctx.children.get(0).getText())) {
ParseTree tree = ctx.children.get(1);
SearchSourceBuilder sourceBuilder = MergeUtils.MergeNot(treeProperty.get(tree));
treeProperty.put(ctx, sourceBuilder);
} else {
ParseTree tree = ctx.children.get(2);
SearchSourceBuilder sourceBuilder = MergeUtils.MergeNot(treeProperty.get(tree));
treeProperty.put(ctx, MergeUtils.MergeAnd(treeProperty.get(ctx.children.get(0)), sourceBuilder));
}
}

@Override
Expand Down Expand Up @@ -211,9 +217,9 @@ public void exitEqExpr(EsQueryParser.EqExprContext ctx) {
}
default: {
if (value.getValue().toString().startsWith(DOUBLE_QUOTATION_MARK_SEPARATOR)) {
boolQueryBuilder.must(QueryBuilders.matchPhraseQuery(param, value.getValue()));
boolQueryBuilder.must(QueryBuilders.matchQuery(param, value.getValue().toString().substring(1)));
} else {
boolQueryBuilder.must(QueryBuilders.matchQuery(param, value.getValue()));
boolQueryBuilder.must(QueryBuilders.matchPhraseQuery(param, value.getValue()));
}
}
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public EsQueryLexer(CharStream input) {
"\u0003\u0000\u0000\u01b0\u01bb\u0007\u0003\u0000\u0000\u01b1\u01b2\u0005"+
"2\u0000\u0000\u01b2\u01b3\u0007\b\u0000\u0000\u01b3\u01bb\u00055\u0000"+
"\u0000\u01b4\u01b5\u00052\u0000\u0000\u01b5\u01b6\u0007\b\u0000\u0000"+
"\u01b6\u01bb\u0007\b\u0000\u0000\u01b7\u01b8\u0007\t\u0000\u0000\u01b8"+
"\u01b6\u01bb\u0007\u0003\u0000\u0000\u01b7\u01b8\u0007\t\u0000\u0000\u01b8"+
"\u01b9\u00055\u0000\u0000\u01b9\u01bb\u0007\b\u0000\u0000\u01ba\u01ab"+
"\u0001\u0000\u0000\u0000\u01ba\u01ac\u0001\u0000\u0000\u0000\u01ba\u01ae"+
"\u0001\u0000\u0000\u0000\u01ba\u01b1\u0001\u0000\u0000\u0000\u01ba\u01b4"+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,39 @@ public void test13(){
public void test14(){
// String str = "linenumber< 128";
// String str = "level in [\"ERROR\",\"INFO\"]";
String str = "level in [ERROR,INFO]";
String str = "message : \"send mq message, topic: kfs-return-visit-result\"";
String esQuery = EsQueryUtils.getEsQuery(str);
System.out.println(esQuery);
}


@Test
public void test15(){
// String str = "linenumber< 128";
// String str = "level in [\"ERROR\",\"INFO\"]";
String str = "message : \"~send mq message, topic: kfs-return-visit-result\"";
SearchSourceBuilder esQuery = EsQueryUtils.getSearchSourceBuilder(str);
System.out.println(esQuery.query());
}

@Test
public void test16(){
String str = "230727436807811 and not \"OfflineOrderServiceImpl.orderOfflineList\"";
SearchSourceBuilder esQuery = EsQueryUtils.getSearchSourceBuilder(str);
System.out.println(esQuery.query());
}

@Test
public void test17(){
String str = "230727436807811 not \"OfflineOrderServiceImpl.orderOfflineList\"";
SearchSourceBuilder esQuery = EsQueryUtils.getSearchSourceBuilder(str);
System.out.println(esQuery.query());
}

@Test
public void test18(){
String str = "linenumber:39058 and logip:10.126.248.201 and tail:\"matrix_dk-system-api-c4\"";
SearchSourceBuilder esQuery = EsQueryUtils.getSearchSourceBuilder(str);
System.out.println(esQuery.query());
}
}