Skip to content

Commit 9bba8d4

Browse files
committed
Merge branch 'zeedeveloper-master'
2 parents ab6121d + 0893e33 commit 9bba8d4

File tree

7 files changed

+38
-22
lines changed

7 files changed

+38
-22
lines changed

module/app/com/github/cleverage/elasticsearch/AsyncUtils.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.cleverage.elasticsearch
22

3+
import org.elasticsearch.client.Client
4+
35
import concurrent.{Future, Promise}
46
import org.elasticsearch.action.{ActionResponse, ActionRequest, ActionListener, ActionRequestBuilder}
57
import play.libs.F
@@ -19,7 +21,7 @@ object AsyncUtils {
1921
* @param requestBuilder
2022
* @return
2123
*/
22-
def executeAsync[RQ <: ActionRequest[RQ],RS <: ActionResponse, RB <: ActionRequestBuilder[RQ,RS,RB]](requestBuilder: ActionRequestBuilder[RQ,RS,RB]): Future[RS] = {
24+
def executeAsync[RQ <: ActionRequest[RQ],RS <: ActionResponse, RB <: ActionRequestBuilder[RQ,RS,RB,CL], CL <: Client](requestBuilder: ActionRequestBuilder[RQ,RS,RB,CL]): Future[RS] = {
2325
val promise = Promise[RS]()
2426

2527
requestBuilder.execute(new ActionListener[RS] {
@@ -40,7 +42,7 @@ object AsyncUtils {
4042
* @param requestBuilder
4143
* @return
4244
*/
43-
def executeAsyncJava[RQ <: ActionRequest[RQ],RS <: ActionResponse, RB <: ActionRequestBuilder[RQ,RS,RB]](requestBuilder: ActionRequestBuilder[RQ,RS,RB]): F.Promise[RS] = {
45+
def executeAsyncJava[RQ <: ActionRequest[RQ],RS <: ActionResponse, RB <: ActionRequestBuilder[RQ,RS,RB,CL], CL <: Client](requestBuilder: ActionRequestBuilder[RQ,RS,RB,CL]): F.Promise[RS] = {
4446
F.Promise.wrap(executeAsync(requestBuilder))
4547
}
4648

module/app/com/github/cleverage/elasticsearch/Index.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.elasticsearch.action.index.IndexResponse;
66
import org.elasticsearch.action.update.UpdateResponse;
77
import org.elasticsearch.index.query.FilterBuilder;
8+
import org.elasticsearch.script.ScriptService;
89
import org.elasticsearch.search.SearchHit;
910

1011
import play.Logger;
@@ -94,20 +95,20 @@ public F.Promise<IndexResponse> indexAsync(String indexName) {
9495
return IndexService.indexAsync(getIndexPath(indexName), id, this);
9596
}
9697

97-
public UpdateResponse update(Map<String,Object> updateFieldValues , String updateScript){
98-
return IndexService.update(getIndexPath(), id, updateFieldValues, updateScript);
98+
public UpdateResponse update(Map<String,Object> updateFieldValues , String updateScript, ScriptService.ScriptType scriptType){
99+
return IndexService.update(getIndexPath(), id, updateFieldValues, updateScript, scriptType);
99100
}
100101

101-
public UpdateResponse update(String indexName, Map<String,Object> updateFieldValues , String updateScript){
102-
return IndexService.update(getIndexPath(indexName), id, updateFieldValues, updateScript);
102+
public UpdateResponse update(String indexName, Map<String,Object> updateFieldValues , String updateScript, ScriptService.ScriptType scriptType){
103+
return IndexService.update(getIndexPath(indexName), id, updateFieldValues, updateScript, scriptType);
103104
}
104105

105-
public F.Promise<UpdateResponse> updateAsync(Map<String,Object> updateFieldValues , String updateScript){
106-
return IndexService.updateAsync(getIndexPath(), id, updateFieldValues, updateScript);
106+
public F.Promise<UpdateResponse> updateAsync(Map<String,Object> updateFieldValues , String updateScript, ScriptService.ScriptType scriptType){
107+
return IndexService.updateAsync(getIndexPath(), id, updateFieldValues, updateScript, scriptType);
107108
}
108109

109-
public F.Promise<UpdateResponse> updateAsync(String indexName, Map<String,Object> updateFieldValues , String updateScript){
110-
return IndexService.updateAsync(getIndexPath(indexName), id, updateFieldValues, updateScript);
110+
public F.Promise<UpdateResponse> updateAsync(String indexName, Map<String,Object> updateFieldValues , String updateScript, ScriptService.ScriptType scriptType){
111+
return IndexService.updateAsync(getIndexPath(indexName), id, updateFieldValues, updateScript, scriptType);
111112
}
112113

113114
/**

module/app/com/github/cleverage/elasticsearch/IndexConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public class IndexConfig {
8787
*/
8888
public boolean dropOnShutdown = false;
8989

90+
/**
91+
* Drop the index on application shutdown
92+
* Should probably be used only in tests
93+
*/
94+
public boolean routingReqd = false;
95+
9096
/**
9197
* Play application
9298
*/

module/app/com/github/cleverage/elasticsearch/IndexQuery.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class IndexQuery<T extends Index> {
5151
private boolean explain = false;
5252
private boolean noField = false;
5353
private String preference = null;
54+
private String route = null;
5455

5556
public IndexQuery(Class<T> clazz) {
5657
Validate.notNull(clazz, "clazz cannot be null");
@@ -178,7 +179,6 @@ public IndexResults<T> fetch(IndexQueryPath indexQueryPath){
178179
public IndexResults<T> fetch(IndexQueryPath indexQueryPath, FilterBuilder filter) {
179180

180181
SearchRequestBuilder request = getSearchRequestBuilder(indexQueryPath, filter);
181-
182182
return executeSearchRequest(request);
183183
}
184184

@@ -276,6 +276,10 @@ public SearchRequestBuilder getSearchRequestBuilder(IndexQueryPath indexQueryPat
276276
request.setPreference(preference);
277277
}
278278

279+
if(route != null){
280+
request.setRouting(route);
281+
}
282+
279283
if (IndexClient.config.showRequest) {
280284
if (StringUtils.isNotBlank(query)) {
281285
Logger.debug("ElasticSearch : Query -> " + query);

module/app/com/github/cleverage/elasticsearch/IndexService.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.index.query.FilterBuilder;
2929
import org.elasticsearch.index.query.QueryBuilder;
3030
import org.elasticsearch.indices.IndexMissingException;
31+
import org.elasticsearch.script.ScriptService;
3132
import play.Logger;
3233
import play.libs.F;
3334

@@ -238,10 +239,10 @@ public static BulkResponse indexBulk(IndexQueryPath indexPath, Map<String, Strin
238239
public static UpdateRequestBuilder getUpdateRequestBuilder(IndexQueryPath indexPath,
239240
String id,
240241
Map<String, Object> updateFieldValues,
241-
String updateScript) {
242+
String updateScript, ScriptService.ScriptType scriptType) {
242243
return IndexClient.client.prepareUpdate(indexPath.index, indexPath.type, id)
243244
.setScriptParams(updateFieldValues)
244-
.setScript(updateScript);
245+
.setScript(updateScript, scriptType);
245246
}
246247

247248
/**
@@ -255,8 +256,8 @@ public static UpdateRequestBuilder getUpdateRequestBuilder(IndexQueryPath indexP
255256
public static UpdateResponse update(IndexQueryPath indexPath,
256257
String id,
257258
Map<String, Object> updateFieldValues,
258-
String updateScript) {
259-
return getUpdateRequestBuilder(indexPath, id, updateFieldValues, updateScript)
259+
String updateScript, ScriptService.ScriptType scriptType) {
260+
return getUpdateRequestBuilder(indexPath, id, updateFieldValues, updateScript, scriptType)
260261
.execute()
261262
.actionGet();
262263
}
@@ -272,8 +273,8 @@ public static UpdateResponse update(IndexQueryPath indexPath,
272273
public static F.Promise<UpdateResponse> updateAsync(IndexQueryPath indexPath,
273274
String id,
274275
Map<String, Object> updateFieldValues,
275-
String updateScript) {
276-
return updateAsync(getUpdateRequestBuilder(indexPath, id, updateFieldValues, updateScript));
276+
String updateScript, ScriptService.ScriptType scriptType) {
277+
return updateAsync(getUpdateRequestBuilder(indexPath, id, updateFieldValues, updateScript, scriptType));
277278
}
278279

279280
/**

module/build.sbt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import xerial.sbt.Sonatype._
55

66
name := "play2-elasticsearch"
77

8-
version := "1.1-SNAPSHOT"
8+
version := "1.2-SNAPSHOT"
99

1010
libraryDependencies ++= Seq(
1111
javaCore,
1212
// Add your project dependencies here
13-
"org.elasticsearch" % "elasticsearch" % "1.1.0",
13+
"org.elasticsearch" % "elasticsearch" % "1.4.0",
14+
"org.codehaus.groovy" % "groovy-all" % "2.3.8",
1415
"org.apache.commons" % "commons-lang3" % "3.1"
1516
)
1617

module/test/ElasticsearchTestJava.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.index.query.FilterBuilders;
1111
import org.elasticsearch.index.query.GeoDistanceFilterBuilder;
1212
import org.elasticsearch.index.query.QueryBuilders;
13+
import org.elasticsearch.script.ScriptService;
1314
import org.junit.Test;
1415
import play.libs.F;
1516
import play.test.FakeApplication;
@@ -244,17 +245,17 @@ public void run() {
244245
GeoPoint location = new GeoPoint(30.6943566,-88.0430541);
245246
Index1Type1 index1Type1 = new Index1Type1("1", "name1", "category", new Date(),location);
246247
index1Type1.index();
247-
Map<String, Object> fieldNewValues = new HashMap<>();
248+
Map<String, Object> fieldNewValues = new HashMap();
248249
fieldNewValues.put("name", "new-name");
249250
String updateScript = "ctx._source.name = name";
250-
index1Type1.update(fieldNewValues, updateScript);
251+
index1Type1.update(fieldNewValues, updateScript, ScriptService.ScriptType.INLINE);
251252

252253
Index1Type1 index1Type11 = Index1Type1.find.byId("1");
253254
assertThat(index1Type11.name).isEqualTo("new-name");
254255

255256
// Async
256257
fieldNewValues.put("name","new-name-async");
257-
F.Promise<UpdateResponse> updateResponsePromise = index1Type1.updateAsync(fieldNewValues, updateScript);
258+
F.Promise<UpdateResponse> updateResponsePromise = index1Type1.updateAsync(fieldNewValues, updateScript, ScriptService.ScriptType.INLINE);
258259
updateResponsePromise.get(2L, TimeUnit.SECONDS);
259260

260261
index1Type11 = Index1Type1.find.byId("1");

0 commit comments

Comments
 (0)