Skip to content

Commit 246ad0c

Browse files
committed
es 5.5.0 support
1 parent cd3fb24 commit 246ad0c

File tree

11 files changed

+27
-25
lines changed

11 files changed

+27
-25
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ before_install:
1717
# update to java 8
1818
- sudo update-java-alternatives -s java-8-oracle
1919
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
20-
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.3.deb && sudo dpkg -i --force-confnew elasticsearch-5.4.3.deb
20+
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb && sudo dpkg -i --force-confnew elasticsearch-5.5.0.deb
2121
- sudo cp ./src/test/resources/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
2222
- sudo cat /etc/elasticsearch/elasticsearch.yml
2323
- 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>5.4.3.0</version>
6+
<version>5.5.0.0</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>
@@ -47,7 +47,7 @@
4747
<elasticsearch.plugin.name>sql</elasticsearch.plugin.name>
4848
<elasticsearch.plugin.site>true</elasticsearch.plugin.site>
4949
<elasticsearch.plugin.jvm>true</elasticsearch.plugin.jvm>
50-
<elasticsearch.version>5.4.3</elasticsearch.version>
50+
<elasticsearch.version>5.5.0</elasticsearch.version>
5151
<elasticsearch.plugin.classname>org.elasticsearch.plugin.nlpcn.SqlPlug</elasticsearch.plugin.classname>
5252
</properties>
5353

src/main/java/org/elasticsearch/plugin/nlpcn/executors/ElasticDefaultRestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.elasticsearch.action.search.SearchRequest;
77
import org.elasticsearch.action.search.SearchResponse;
88
import org.elasticsearch.client.Client;
9-
import org.elasticsearch.action.bulk.byscroll.DeleteByQueryRequest;
9+
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
1010
import org.elasticsearch.plugin.nlpcn.*;
1111
import org.elasticsearch.rest.BytesRestResponse;
1212
import org.elasticsearch.rest.RestChannel;

src/main/java/org/nlpcn/es4sql/query/AggregationQueryAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.elasticsearch.action.search.SearchType;
1010
import org.elasticsearch.client.Client;
1111
import org.elasticsearch.index.query.QueryBuilder;
12+
import org.elasticsearch.join.aggregations.JoinAggregationBuilders;
1213
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
1314
import org.elasticsearch.search.aggregations.AggregationBuilder;
1415
import org.elasticsearch.search.aggregations.AggregationBuilders;
@@ -238,7 +239,7 @@ private AggregationBuilder createChildrenAggregation(Field field) {
238239

239240
String childType = field.getChildType();
240241

241-
childrenBuilder = AggregationBuilders.children(getChildrenAggName(field),childType);
242+
childrenBuilder = JoinAggregationBuilders.children(getChildrenAggName(field),childType);
242243

243244
return childrenBuilder;
244245
}

src/main/java/org/nlpcn/es4sql/query/DeleteQueryAction.java

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

77
import org.elasticsearch.index.query.QueryBuilders;
88
import org.elasticsearch.index.reindex.DeleteByQueryAction;
9-
import org.elasticsearch.action.bulk.byscroll.DeleteByQueryRequest;
9+
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
1010
import org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder;
1111
import org.nlpcn.es4sql.domain.Delete;
1212
import org.nlpcn.es4sql.domain.Where;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.math.BigDecimal;
44
import java.util.*;
55

6+
import org.elasticsearch.join.aggregations.JoinAggregationBuilders;
67
import org.elasticsearch.script.Script;
78
import org.elasticsearch.script.ScriptService;
89
import org.elasticsearch.script.ScriptType;
@@ -194,7 +195,7 @@ private AggregationBuilder addFieldToAgg(MethodField field, ValuesSourceAggregat
194195

195196
String childrenAggName = childrenType.field + "@CHILDREN";
196197

197-
childrenBuilder = AggregationBuilders.children(childrenAggName,childrenType.childType);
198+
childrenBuilder = JoinAggregationBuilders.children(childrenAggName,childrenType.childType);
198199

199200
return childrenBuilder;
200201
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.common.xcontent.XContentParser;
1717
import org.elasticsearch.common.xcontent.json.JsonXContent;
1818
import org.elasticsearch.index.query.*;
19+
import org.elasticsearch.join.query.JoinQueryBuilders;
1920
import org.elasticsearch.script.Script;
2021
import org.elasticsearch.script.ScriptService;
2122
import org.nlpcn.es4sql.Util;
@@ -265,7 +266,7 @@ private ToXContent make(Condition cond, String name, Object value) throws SqlPar
265266
Where whereChildren = (Where) value;
266267
BoolQueryBuilder childrenFilter = QueryMaker.explan(whereChildren);
267268
//todo: pass score mode
268-
x = QueryBuilders.hasChildQuery(name, childrenFilter,ScoreMode.None);
269+
x = JoinQueryBuilders.hasChildQuery(name, childrenFilter,ScoreMode.None);
269270

270271
break;
271272
case SCRIPT:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.elasticsearch.index.query.BoolQueryBuilder;
66
import org.elasticsearch.index.query.QueryBuilder;
77
import org.elasticsearch.index.query.QueryBuilders;
8+
import org.elasticsearch.join.query.JoinQueryBuilders;
89
import org.nlpcn.es4sql.domain.Condition;
910
import org.nlpcn.es4sql.domain.Where;
1011
import org.nlpcn.es4sql.domain.Where.CONN;
@@ -65,7 +66,7 @@ private void addSubQuery(BoolQueryBuilder boolQuery, Where where, QueryBuilder s
6566
if(condition.isNested()){
6667
subQuery = QueryBuilders.nestedQuery(condition.getNestedPath(), subQuery, ScoreMode.None);
6768
} else if(condition.isChildren()) {
68-
subQuery = QueryBuilders.hasChildQuery(condition.getChildType(), subQuery, ScoreMode.None);
69+
subQuery = JoinQueryBuilders.hasChildQuery(condition.getChildType(), subQuery, ScoreMode.None);
6970
}
7071
}
7172

src/test/java/org/nlpcn/es4sql/AggregationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public void topHitTest() throws IOException, SqlParseException, SQLFeatureNotSup
394394
@Test
395395
public void topHitTest_WithInclude() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
396396
Aggregations result = query(String.format("select topHits('size'=3,age='desc',include=age) from %s/account group by gender ", TEST_INDEX));
397-
List<Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets();
397+
List<? extends Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets();
398398
for (Terms.Bucket bucket : buckets){
399399
SearchHits hits = ((InternalTopHits) bucket.getAggregations().asList().get(0)).getHits();
400400
for(SearchHit hit: hits ){
@@ -408,7 +408,7 @@ public void topHitTest_WithInclude() throws IOException, SqlParseException, SQLF
408408
@Test
409409
public void topHitTest_WithIncludeTwoFields() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
410410
Aggregations result = query(String.format("select topHits('size'=3,'include'='age,firstname',age='desc') from %s/account group by gender ", TEST_INDEX));
411-
List<Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets();
411+
List<? extends Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets();
412412
for (Terms.Bucket bucket : buckets){
413413
SearchHits hits = ((InternalTopHits) bucket.getAggregations().asList().get(0)).getHits();
414414
for(SearchHit hit: hits ){
@@ -423,7 +423,7 @@ public void topHitTest_WithIncludeTwoFields() throws IOException, SqlParseExcept
423423
@Test
424424
public void topHitTest_WithExclude() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
425425
Aggregations result = query(String.format("select topHits('size'=3,'exclude'='lastname',age='desc') from %s/account group by gender ", TEST_INDEX));
426-
List<Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets();
426+
List<? extends Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets();
427427
for (Terms.Bucket bucket : buckets){
428428
SearchHits hits = ((InternalTopHits) bucket.getAggregations().asList().get(0)).getHits();
429429
for(SearchHit hit: hits ){
@@ -436,7 +436,7 @@ public void topHitTest_WithExclude() throws IOException, SqlParseException, SQLF
436436
@Test
437437
public void topHitTest_WithIncludeAndExclude() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
438438
Aggregations result = query(String.format("select topHits('size'=3,'exclude'='lastname','include'='firstname,lastname',age='desc') from %s/account group by gender ", TEST_INDEX));
439-
List<Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets();
439+
List<? extends Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets();
440440
for (Terms.Bucket bucket : buckets) {
441441
SearchHits hits = ((InternalTopHits) bucket.getAggregations().asList().get(0)).getHits();
442442
for (SearchHit hit : hits) {

src/test/java/org/nlpcn/es4sql/MainTestSuite.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.client.transport.TransportClient;
1515
import org.elasticsearch.common.settings.Settings;
1616
import org.elasticsearch.common.transport.InetSocketTransportAddress;
17+
import org.elasticsearch.common.xcontent.XContentFactory;
1718
import org.elasticsearch.index.query.QueryBuilders;
1819
import org.elasticsearch.index.reindex.DeleteByQueryAction;
1920
import org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder;
@@ -130,7 +131,7 @@ private static void prepareGameOfThronesIndex() {
130131
"}\n" +
131132
"}"+
132133
"} } }";
133-
client.admin().indices().preparePutMapping(TEST_INDEX).setType("gotCharacters").setSource(dataMapping).execute().actionGet();
134+
client.admin().indices().preparePutMapping(TEST_INDEX).setType("gotCharacters").setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
134135
}
135136

136137
private static void prepareDogsIndex() {
@@ -143,7 +144,7 @@ private static void prepareDogsIndex() {
143144
" }"+
144145
" }" +
145146
"}";
146-
client.admin().indices().preparePutMapping(TEST_INDEX).setType("dog").setSource(dataMapping).execute().actionGet();
147+
client.admin().indices().preparePutMapping(TEST_INDEX).setType("dog").setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
147148
}
148149

149150
private static void prepareAccountsIndex() {
@@ -164,7 +165,7 @@ private static void prepareAccountsIndex() {
164165
" }"+
165166
" }" +
166167
"}";
167-
client.admin().indices().preparePutMapping(TEST_INDEX).setType("account").setSource(dataMapping).execute().actionGet();
168+
client.admin().indices().preparePutMapping(TEST_INDEX).setType("account").setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
168169
}
169170

170171

@@ -181,7 +182,7 @@ private static void preparePhrasesIndex() {
181182
" }"+
182183
" }" +
183184
"}";
184-
client.admin().indices().preparePutMapping(TEST_INDEX).setType("phrase").setSource(dataMapping).execute().actionGet();
185+
client.admin().indices().preparePutMapping(TEST_INDEX).setType("phrase").setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
185186
}
186187

187188
private static void prepareNestedTypeIndex() {
@@ -227,7 +228,7 @@ private static void prepareNestedTypeIndex() {
227228
" }\n" +
228229
" }}";
229230

230-
client.admin().indices().preparePutMapping(TEST_INDEX).setType("nestedType").setSource(dataMapping).execute().actionGet();
231+
client.admin().indices().preparePutMapping(TEST_INDEX).setType("nestedType").setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
231232
}
232233

233234
private static void prepareChildrenTypeIndex() {
@@ -256,7 +257,7 @@ private static void prepareChildrenTypeIndex() {
256257
" }"+
257258
"}\n";
258259

259-
client.admin().indices().preparePutMapping(TEST_INDEX).setType("childrenType").setSource(dataMapping).execute().actionGet();
260+
client.admin().indices().preparePutMapping(TEST_INDEX).setType("childrenType").setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
260261
}
261262

262263
private static void prepareParentTypeIndex() {
@@ -272,7 +273,7 @@ private static void prepareParentTypeIndex() {
272273
" }\n" +
273274
"}\n";
274275

275-
client.admin().indices().preparePutMapping(TEST_INDEX).setType("parentType").setSource(dataMapping).execute().actionGet();
276+
client.admin().indices().preparePutMapping(TEST_INDEX).setType("parentType").setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
276277
}
277278

278279
@AfterClass
@@ -346,7 +347,7 @@ public static void prepareSpatialIndex(String type){
346347
"\t}\n" +
347348
"}";
348349

349-
client.admin().indices().preparePutMapping(TEST_INDEX).setType(type).setSource(dataMapping).execute().actionGet();
350+
client.admin().indices().preparePutMapping(TEST_INDEX).setType(type).setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
350351
}
351352
public static void prepareOdbcIndex(){
352353
String dataMapping = "{\n" +
@@ -363,7 +364,7 @@ public static void prepareOdbcIndex(){
363364
"\t}\n" +
364365
"}";
365366

366-
client.admin().indices().preparePutMapping(TEST_INDEX).setType("odbc").setSource(dataMapping).execute().actionGet();
367+
client.admin().indices().preparePutMapping(TEST_INDEX).setType("odbc").setSource(dataMapping, XContentFactory.xContentType(dataMapping)).execute().actionGet();
367368
}
368369

369370
public static SearchDao getSearchDao() {

0 commit comments

Comments
 (0)