Skip to content

Commit 4e7ef83

Browse files
committed
es 9.1.8 support
1 parent f537d90 commit 4e7ef83

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

.github/workflows/actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- name: Install Elasticsearch
2121
env:
22-
ES_VERSION: 9.1.4
22+
ES_VERSION: 9.1.8
2323
run: |
2424
sudo rm -rf /var/lib/elasticsearch
2525
curl -fsSL --retry 3 --retry-delay 5 "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-amd64.deb" -o elasticsearch.deb

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jdk:
66

77
before_install:
88
- sudo rm -rf /var/lib/elasticsearch
9-
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-9.1.4-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
9+
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-9.1.8-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
1010
- sudo cp ./src/test/resources/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
1111
- sudo cat /etc/elasticsearch/elasticsearch.yml
1212
- sudo java -version

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.nlpcn</groupId>
55
<artifactId>elasticsearch-sql</artifactId>
6-
<version>9.1.4.0</version>
6+
<version>9.1.8.0</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>
@@ -44,7 +44,7 @@
4444
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4545
<runSuite>**/MainTestSuite.class</runSuite>
4646
<elasticsearch.plugin.name>sql</elasticsearch.plugin.name>
47-
<elasticsearch.version>9.1.4</elasticsearch.version>
47+
<elasticsearch.version>9.1.8</elasticsearch.version>
4848
<elasticsearch.plugin.classname>org.elasticsearch.plugin.nlpcn.SqlPlug</elasticsearch.plugin.classname>
4949
<druid.version>1.2.15</druid.version>
5050
<guava.version>32.0.0-jre</guava.version>

src/main/java/org/nlpcn/es4sql/Util.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ public static Object getScriptValueWithQuote(SQLExpr expr, String quote) throws
128128
return ((SQLNullExpr) expr).toString().toLowerCase();
129129
} else if (expr instanceof SQLBinaryOpExpr) {
130130
//zhongshu-comment 该分支由忠树添加
131-
String left = "doc['" + ((SQLBinaryOpExpr) expr).getLeft().toString() + "'].value";
132-
String operator = ((SQLBinaryOpExpr) expr).getOperator().getName();
133-
String right = "doc['" + ((SQLBinaryOpExpr) expr).getRight().toString() + "'].value";
131+
SQLBinaryOpExpr sqlExpr = (SQLBinaryOpExpr) expr;
132+
Object leftValue = getScriptValueWithQuote(sqlExpr.getLeft(), quote);
133+
String left = sqlExpr.getLeft() instanceof SQLBinaryOpExpr ? "(" + leftValue + ")" : leftValue.toString();
134+
String operator = sqlExpr.getOperator().getName();
135+
Object rightValue = getScriptValueWithQuote(sqlExpr.getRight(), quote);
136+
String right = sqlExpr.getRight() instanceof SQLBinaryOpExpr ? "(" + rightValue + ")" : rightValue.toString();
134137
return left + operator + right;
135138
}
136139
throw new SqlParseException("could not parse sqlBinaryOpExpr need to be identifier/valuable got " + expr.getClass().toString() + " with value:" + expr.toString());

src/main/java/org/nlpcn/es4sql/query/maker/AggMaker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private AggregationBuilder termsAgg(MethodField field) throws SqlParseException
391391
IncludeExclude include = null, exclude = null;
392392
for (KVValue kv : field.getParams()) {
393393
if(kv.value.toString().contains("doc[")) {
394-
String script = kv.value + "; return " + kv.key;
394+
String script = kv.value.toString();
395395
terms.script(new Script(script));
396396
} else {
397397
value = kv.value.toString();
@@ -665,7 +665,7 @@ private DateHistogramAggregationBuilder dateHistogram(MethodField field) throws
665665
String value = null;
666666
for (KVValue kv : field.getParams()) {
667667
if(kv.value.toString().contains("doc[")) {
668-
String script = kv.value + "; return " + kv.key;
668+
String script = kv.value.toString();
669669
dateHistogram.script(new Script(script));
670670
} else {
671671
value = kv.value.toString();
@@ -750,7 +750,7 @@ private HistogramAggregationBuilder histogram(MethodField field) throws SqlParse
750750
String value = null;
751751
for (KVValue kv : field.getParams()) {
752752
if(kv.value.toString().contains("doc[")) {
753-
String script = kv.value + "; return " + kv.key;
753+
String script = kv.value.toString();
754754
histogram.script(new Script(script));
755755
} else {
756756
value = kv.value.toString();

0 commit comments

Comments
 (0)