Skip to content

Commit ba6ae34

Browse files
Groovy scripts example for feature #87
1 parent f98cec0 commit ba6ae34

8 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import org.joda.time.DateTime
2+
logger.debug("Incoming document: {}", ctx.document)
3+
def today = new DateTime()
4+
println "Today: ${today}"
5+
ctx.document.monthOfYear = today.monthOfYear
6+
logger.debug("Outgoing document: {}", ctx.document)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
logger.debug("Incoming document: {}", ctx.document)
2+
def now = new Date()
3+
println "Now: ${now}"
4+
ctx.document.modified = now.clearTime()
5+
logger.debug("Outgoing document: {}", ctx.document)

Diff for: resources/issues/87/01_create-river-groovy.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
curl -XPUT "http://localhost:9200/_river/mongodb87/_meta" -d @mongodb-river-groovy.json

Diff for: resources/issues/87/02_test-issue-87.bat

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%MONGO_HOME%\bin\mongo < test-import-document.js
2+
pause
3+
curl -XGET localhost:9200/mydb-87/_search?q=firstName:John
4+
pause
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REM Copy joda-time-x-y.jar in $ES_HOME\lib
2+
curl -XPUT "http://localhost:9200/_river/mongodb87/_meta" -d @mongodb-river-groovy-jodatime.json
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type": "mongodb",
3+
"mongodb": {
4+
"db": "mydb87",
5+
"collection": "mycollec87",
6+
"scriptType": "groovy",
7+
"script": "testjodatime"
8+
},
9+
"index": {
10+
"name": "mydb-87",
11+
"type": "mycollec-87"
12+
}
13+
}

Diff for: resources/issues/87/mongodb-river-groovy.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type": "mongodb",
3+
"mongodb": {
4+
"db": "mydb87",
5+
"collection": "mycollec87",
6+
"scriptType": "groovy",
7+
"script": "testscript"
8+
},
9+
"index": {
10+
"name": "mydb-87",
11+
"type": "mycollec-87"
12+
}
13+
}

Diff for: resources/issues/87/test-import-document.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use mydb87
2+
var o =
3+
{
4+
"firstName": "John",
5+
"lastName": "Doe",
6+
"created": new Date()
7+
}
8+
9+
db.mycollec87.save(o)

0 commit comments

Comments
 (0)