Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a63db5

Browse files
committed
Merge branch 'elastic2.1.2' into elastic2.2.0
Conflicts: .travis.yml pom.xml src/main/java/org/elasticsearch/plugin/nlpcn/NestedLoopsElasticExecutor.java
2 parents 79f8163 + d049849 commit 4a63db5

26 files changed

+594
-71
lines changed

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ Elasticsearch-SQL
22
=================
33
**1.X** [![1.X Build Status](https://travis-ci.org/NLPchina/elasticsearch-sql.svg?branch=master)](https://travis-ci.org/NLPchina/elasticsearch-sql) <br>
44
**2.0.0** [![2.0.0 Build Status](https://travis-ci.org/NLPchina/elasticsearch-sql.svg?branch=elastic2.0)](https://travis-ci.org/NLPchina/elasticsearch-sql)<br>
5-
**2.1.0** [![2.1.0 Build Status](https://travis-ci.org/NLPchina/elasticsearch-sql.svg?branch=elastic2.0)](https://travis-ci.org/NLPchina/elasticsearch-sql)<br>
5+
**2.1.0** [![2.1.0 Build Status](https://travis-ci.org/NLPchina/elasticsearch-sql.svg?branch=elastic2.1)](https://travis-ci.org/NLPchina/elasticsearch-sql)<br>
6+
**2.1.1** [![2.1.1 Build Status](https://travis-ci.org/NLPchina/elasticsearch-sql.svg?branch=elastic2.1.1)](https://travis-ci.org/NLPchina/elasticsearch-sql)<br>
67

78
Query elasticsearch using familiar SQL syntax.
89
You can also use ES functions in SQL.
@@ -21,23 +22,33 @@ Install as plugin:
2122
Versions
2223
------------
2324

24-
| elasticsearch version | latest version | remarks | branch |
25-
| --------------------- | ------------- | ----------------------------- | ---------- |
26-
| 1.X | 1.4.7 | tested against elastic 1.4-1.6 | master |
27-
| 2.0.0 | 2.0.2 | delete commands not supported | elastic2.0 |
28-
| 2.1.0 | 2.1.0 | delete commands not supported | elastic2.1 |
25+
| elasticsearch version | latest version | remarks | branch |
26+
| --------------------- | ------------- | ----------------------------- | ------------ |
27+
| 1.X | 1.4.8 | tested against elastic 1.4-1.6 | master |
28+
| 2.0.0 | 2.0.3 | delete commands not supported | elastic2.0 |
29+
| 2.1.0 | 2.1.0.1 | delete commands not supported | elastic2.1 |
30+
| 2.1.1 | 2.1.1 | delete commands not supported | elastic2.1.1 |
31+
| 2.2.0 | 2.2.0 | delete commands not supported | elastic2.2.0 |
2932

3033
### Elasticsearch 1.X
3134
````
32-
./bin/plugin -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.4.7/elasticsearch-sql-1.4.7.zip --install sql
35+
./bin/plugin -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.4.8/elasticsearch-sql-1.4.8.zip --install sql
3336
````
3437
### Elasticsearch 2.0.0
3538
````
36-
./bin/plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/2.0.2/elasticsearch-sql-2.0.2.zip
39+
./bin/plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/2.0.3/elasticsearch-sql-2.0.3.zip
3740
````
3841
### Elasticsearch 2.1.0
3942
````
40-
./bin/plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/2.1.0/elasticsearch-sql-2.1.0.zip
43+
./bin/plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/2.1.0.1/elasticsearch-sql-2.1.0.1.zip
44+
````
45+
### Elasticsearch 2.1.1
46+
````
47+
./bin/plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/2.1.1/elasticsearch-sql-2.1.1.zip
48+
````
49+
### Elasticsearch 2.2.0
50+
````
51+
./bin/plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/2.2.0/elasticsearch-sql-2.2.0.zip
4152
````
4253
After doing this, you need to restart the Elasticsearch server. Otherwise you may get errors like `Invalid index name [sql], must not start with '']; ","status":400}`.
4354

pom.xml

Lines changed: 1 addition & 1 deletion
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>2.2.0</version>
6+
<version>2.2.0.1</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>

src/_site/controllers.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce,$
1616

1717
$scope.scrollId = undefined;
1818
$scope.amountDescription = "";
19-
var optionsKey = "essql-options";
19+
var optionsKey = "essql-options-v1";
2020
var fetched = 0;
2121
var total = 0 ;
2222
//checkboxes
@@ -36,7 +36,9 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce,$
3636
scrollSize : 10,
3737
alwaysScroll : false,
3838
isAutoSave : false,
39-
delimiter : ','
39+
delimiter : ',',
40+
showScore : false,
41+
showType : false
4042
}
4143
if (typeof(Storage) !== "undefined") {
4244
options = localStorage.getItem(optionsKey);
@@ -80,7 +82,7 @@ $scope.fetchAll = function(){
8082

8183
$http.get($scope.url + scroll_url + $scope.scrollId)
8284
.success(function(data, status, headers, config) {
83-
var handler = ResultHandlerFactory.create(data,$scope.config.isFlat);
85+
var handler = ResultHandlerFactory.create(data,$scope.config.isFlat,$scope.config.showScore,$scope.config.showType);
8486
updateDescription(handler);
8587
var body = handler.getBody()
8688

@@ -160,7 +162,7 @@ function updateWithScrollIfNeeded (query) {
160162
query = updateWithScrollIfNeeded(query);
161163
$http.post($scope.url + "_sql", query)
162164
.success(function(data, status, headers, config) {
163-
var handler = ResultHandlerFactory.create(data,$scope.config.isFlat);
165+
var handler = ResultHandlerFactory.create(data,$scope.config.isFlat,$scope.config.showScore,$scope.config.showType);
164166
updateDescription(handler);
165167
if(handler.isScroll){
166168
$scope.showResults=true;

src/_site/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ <h4 class="panel-title">
122122
<div class="checkbox">
123123
<label><input type="checkbox" ng-model="config.useOldTable" ng-change="onChangeTablePresnterType()" value="">Old Table</label>
124124
</div>
125+
<div class="checkbox">
126+
<label><input type="checkbox" ng-model="config.showScore" ng-change="onChangeTablePresnterType()" value="">Show Score</label>
127+
</div>
128+
<div class="checkbox">
129+
<label><input type="checkbox" ng-model="config.showType" ng-change="onChangeTablePresnterType()" value="">Show Type</label>
130+
</div>
125131
<div class="checkbox">
126132
<label><input type="checkbox" ng-model="config.alwaysScroll" ng-change="alwatsScrollChanged()" value="">always scroll</label>
127133
</div>

src/_site/query.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Returns the right Result Handler depend
44
on the results */
55
var ResultHandlerFactory = {
6-
"create": function(data,isFlat) {
6+
"create": function(data,isFlat,showScore,showType) {
77
function isSearch(){
88
return "hits" in data
99
}
@@ -16,7 +16,8 @@ var ResultHandlerFactory = {
1616
}
1717

1818
if(isSearch()){
19-
return isAggregation() ? new AggregationQueryResultHandler(data) : new DefaultQueryResultHandler(data,isFlat)
19+
return isAggregation() ? new AggregationQueryResultHandler(data) :
20+
new DefaultQueryResultHandler(data,isFlat,showScore,showType)
2021
}
2122

2223
if(isDelete()){
@@ -35,7 +36,7 @@ var ResultHandlerFactory = {
3536
in case of regular query
3637
(Not aggregation)
3738
*/
38-
var DefaultQueryResultHandler = function(data,isFlat) {
39+
var DefaultQueryResultHandler = function(data,isFlat,showScore,showType) {
3940

4041
// createScheme by traverse hits field
4142
function createScheme() {
@@ -47,6 +48,7 @@ var DefaultQueryResultHandler = function(data,isFlat) {
4748
if(isFlat){
4849
findKeysRecursive(scheme,header,"");
4950
}
51+
5052
else {
5153
for(key in header) {
5254

@@ -57,14 +59,22 @@ var DefaultQueryResultHandler = function(data,isFlat) {
5759
}
5860

5961
}
62+
if(showType){
63+
scheme.push("_type");
64+
}
65+
if(showScore){
66+
scheme.push("_score");
67+
}
6068
return scheme
6169
}
6270

6371

6472
this.data = data
6573
this.head = createScheme()
6674
this.isFlat = isFlat;
67-
this.scrollId = data["_scroll_id"]
75+
this.showScore = showScore;
76+
this.showType = showType;
77+
this.scrollId = data["_scroll_id"];
6878
this.isScroll = this.scrollId!=undefined && this.scrollId!="";
6979
};
7080

@@ -92,6 +102,12 @@ DefaultQueryResultHandler.prototype.getBody = function() {
92102
if(this.isFlat){
93103
row = flatRow(this.head,row);
94104
}
105+
if(this.showType){
106+
row["_type"] = hits[i]._type
107+
}
108+
if(this.showScore){
109+
row["_score"] = hits[i]._score
110+
}
95111
body.push(row)
96112
}
97113
return body

src/main/java/org/elasticsearch/plugin/nlpcn/ElasticJoinExecutor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ protected Map<String,Object> mapWithAliases(Map<String, Object> source, String a
137137
return mapWithAliases;
138138
}
139139

140-
protected void onlyReturnedFields(Map<String, Object> fieldsMap, List<Field> required) {
140+
protected void onlyReturnedFields(Map<String, Object> fieldsMap, List<Field> required,boolean allRequired) {
141141
HashMap<String,Object> filteredMap = new HashMap<>();
142-
if(allFieldsReturn) {
142+
if(allFieldsReturn || allRequired) {
143143
filteredMap.putAll(fieldsMap);
144144
return;
145145
}
@@ -214,7 +214,9 @@ protected InternalSearchHit createUnmachedResult( List<Field> secondTableReturne
214214
protected Map<String, Object> createNullsSource(List<Field> secondTableReturnedFields) {
215215
Map<String,Object> nulledSource = new HashMap<>();
216216
for(Field field : secondTableReturnedFields){
217-
nulledSource.put(field.getName(),null);
217+
if(!field.getName().equals("*")){
218+
nulledSource.put(field.getName(),null);
219+
}
218220
}
219221
return nulledSource;
220222
}

src/main/java/org/elasticsearch/plugin/nlpcn/HashJoinElasticExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private List<InternalSearchHit> createCombinedResults( TableInJoinRequestBuilder
157157

158158
Map<String,Object> copiedSource = new HashMap<String,Object>();
159159
copyMaps(copiedSource,secondTableHit.sourceAsMap());
160-
onlyReturnedFields(copiedSource, secondTableRequest.getReturnedFields());
160+
onlyReturnedFields(copiedSource, secondTableRequest.getReturnedFields(),secondTableRequest.getOriginalSelect().isSelectAll());
161161

162162

163163

@@ -211,7 +211,7 @@ private void createKeyToResultsAndFillOptimizationStructure(Map<String,Map<Strin
211211
InternalSearchHit searchHit = new InternalSearchHit(resultIds, hit.id(), new Text(hit.getType()), hit.getFields());
212212
searchHit.sourceRef(hit.getSourceRef());
213213

214-
onlyReturnedFields(searchHit.sourceAsMap(), firstTableRequest.getReturnedFields());
214+
onlyReturnedFields(searchHit.sourceAsMap(), firstTableRequest.getReturnedFields(),firstTableRequest.getOriginalSelect().isSelectAll());
215215
resultIds++;
216216
this.hashJoinComparisonStructure.insertIntoComparisonHash(comparisonID, key, searchHit);
217217
}

src/main/java/org/elasticsearch/plugin/nlpcn/NestedLoopsElasticExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private int combineResultsFromMultiResponses(List<InternalSearchHit> combinedRes
8686

8787
for(int j =0 ; j < responses.length && currentCombinedResults < totalLimit ; j++){
8888
SearchHit hitFromFirstTable = hits[currentIndex+j];
89-
onlyReturnedFields(hitFromFirstTable.sourceAsMap(), nestedLoopsRequest.getFirstTable().getReturnedFields());
89+
onlyReturnedFields(hitFromFirstTable.sourceAsMap(), nestedLoopsRequest.getFirstTable().getReturnedFields(),nestedLoopsRequest.getFirstTable().getOriginalSelect().isSelectAll());
9090

9191
SearchResponse multiItemResponse = responses[j].getResponse();
9292
updateMetaSearchResults(multiItemResponse);
@@ -114,7 +114,7 @@ private int combineResultsFromMultiResponses(List<InternalSearchHit> combinedRes
114114
}
115115

116116
private InternalSearchHit getMergedHit(int currentCombinedResults, String t1Alias, String t2Alias, SearchHit hitFromFirstTable, SearchHit matchedHit) {
117-
onlyReturnedFields(matchedHit.sourceAsMap(), nestedLoopsRequest.getSecondTable().getReturnedFields());
117+
onlyReturnedFields(matchedHit.sourceAsMap(), nestedLoopsRequest.getSecondTable().getReturnedFields(),nestedLoopsRequest.getSecondTable().getOriginalSelect().isSelectAll());
118118
InternalSearchHit searchHit = new InternalSearchHit(currentCombinedResults, hitFromFirstTable.id() + "|" + matchedHit.getId(), new Text(hitFromFirstTable.getType() + "|" + matchedHit.getType()), hitFromFirstTable.getFields());
119119
searchHit.sourceRef(hitFromFirstTable.getSourceRef());
120120
searchHit.sourceAsMap().clear();

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public class CSVResultRestExecutor implements RestExecutor {
1818
@Override
1919
public void execute(Client client, Map<String, String> params, QueryAction queryAction, RestChannel channel) throws Exception {
2020
Object queryResult = QueryActionElasticExecutor.executeAnyAction(client, queryAction);
21-
boolean flat = false;
22-
if(params.containsKey("flat")){
23-
flat = Boolean.parseBoolean(params.get("flat"));
24-
}
21+
22+
boolean flat = getBooleanOrDefault(params,"flat",false);
2523
String separator = ",";
2624
if(params.containsKey("separator")){
2725
separator = params.get("separator");
2826
}
29-
CSVResult result = new CSVResultsExtractor().extractResults(queryResult,flat,separator);
27+
boolean includeScore = getBooleanOrDefault(params,"_score",false);
28+
boolean includeType = getBooleanOrDefault(params,"_type",false);
29+
CSVResult result = new CSVResultsExtractor(includeScore,includeType).extractResults(queryResult,flat,separator);
3030
String newLine = "\n";
3131
if(params.containsKey("newLine")){
3232
newLine = params.get("newLine");
@@ -36,6 +36,14 @@ public void execute(Client client, Map<String, String> params, QueryAction query
3636
channel.sendResponse(bytesRestResponse);
3737
}
3838

39+
private boolean getBooleanOrDefault(Map<String, String> params, String param, boolean defaultValue) {
40+
boolean flat = defaultValue;
41+
if(params.containsKey(param)){
42+
flat = Boolean.parseBoolean(params.get(param));
43+
}
44+
return flat;
45+
}
46+
3947
private String buildString(String separator, CSVResult result, String newLine) {
4048
StringBuilder csv = new StringBuilder();
4149
csv.append(Joiner.on(separator).join(result.getHeaders()));

0 commit comments

Comments
 (0)