Skip to content

Commit 4f9a446

Browse files
authored
Merge pull request noamt#158 from Endource/elasticsearch-2.3
Elasticsearch 2.3
2 parents 92a40da + a8d55c7 commit 4f9a446

36 files changed

+580
-401
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ plugin.xml
2727
.project
2828
test/reports
2929
data/
30+
31+
#Elasticserch plugin binaries
32+
src/integration-test/resources/elasticsearch/plugins

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: groovy
22
jdk:
3-
- oraclejdk7
3+
- oraclejdk8
44
before_script:
55
- rm -rf target
66
script: travis_wait 60 ./travis-build.sh

README.asciidoc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,35 @@ Edit your project's +build.gradle+ file, by adding the plugin's dependency decla
1616
----
1717
dependencies {
1818
...
19-
compile "org.grails.plugins:elasticsearch:1.0.0.2"
19+
compile "org.grails.plugins:elasticsearch:2.3.0"
2020
...
2121
2222
}
2323
----
2424

25+
26+
=== Versioning
27+
28+
|===
29+
|Plugin Version | Grails Version | Elasticsearch Version
30+
31+
|2.3.x
32+
|3.y
33+
|2.3.z
34+
35+
|1.0.0.x
36+
|3.y
37+
|1.6.z
38+
39+
|0.1.0.x
40+
|2.y
41+
|2.1.z
42+
43+
|0.0.4.x
44+
|2.y
45+
|1.6.z
46+
|===
47+
2548
=== Ohs Nos! I'm hitting a +java.lang.Exception: No datastore implementation specified+
2649

2750
This error means that you probably haven't specified your datastore type in your +application.groovy+ or +application.yml+ file.

build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ plugins {
1717
id "com.jfrog.bintray" version "1.2"
1818
}
1919

20-
version "1.0.0.2"
20+
version "1.2.0"
2121
group "org.grails.plugins"
2222

2323
apply plugin: 'maven-publish'
@@ -30,11 +30,11 @@ apply plugin: "org.grails.grails-gsp"
3030
ext {
3131
grailsVersion = project.grailsVersion
3232
gradleWrapperVersion = project.gradleWrapperVersion
33-
elasticsearchVersion = "1.0.0.3"
33+
elasticsearchVersion = "2.3.3"
3434
}
3535

36-
sourceCompatibility = 1.7
37-
targetCompatibility = 1.7
36+
sourceCompatibility = 1.8
37+
targetCompatibility = 1.8
3838

3939
repositories {
4040
mavenLocal()
@@ -64,6 +64,8 @@ sourcesJar {
6464
exclude "test/**/**"
6565
}
6666

67+
def elasticsearchVersion = '2.3.3'
68+
6769
dependencies {
6870
provided 'org.springframework.boot:spring-boot-starter-logging'
6971
provided "org.springframework.boot:spring-boot-starter-actuator"
@@ -77,17 +79,16 @@ dependencies {
7779
compile "org.grails.plugins:cache"
7880
compile "org.hibernate:hibernate-ehcache"
7981

80-
testRuntime('org.elasticsearch:elasticsearch-groovy:1.6.0') {
81-
exclude module: 'groovy-all'
82-
}
83-
compile "org.elasticsearch:elasticsearch-mapper-attachments:2.6.0"
82+
compile "org.elasticsearch:elasticsearch:${elasticsearchVersion}"
8483

8584
testRuntime 'com.spatial4j:spatial4j:0.4.1'
8685
testCompile 'com.vividsolutions:jts:1.13'
8786
testCompile 'com.googlecode.json-simple:json-simple:1.1.1'
8887
testCompile "org.grails:grails-plugin-testing"
8988

9089
console "org.grails:grails-console"
90+
91+
compile "org.elasticsearch.plugin:mapper-attachments:${elasticsearchVersion}"
9192
}
9293

9394
task wrapper(type: Wrapper) {

gradle/publish.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ if (bintrayProperties.exists()) {
1515
}
1616
title = "Elasticserach"
1717
desc = "An Elasticsearch plugin for Grails"
18-
developers = [noam: 'Noam Y. Tenne', macrcos: 'Marcos Carceles', puneet: 'Puneet Behl', james: 'James Kleeh']
18+
developers = [noam: 'Noam Y. Tenne', marcos: 'Marcos Carceles', puneet: 'Puneet Behl', james: 'James Kleeh']
19+
}
20+
} else {
21+
grailsPublish {
22+
githubSlug = 'noamt/elasticsearch-grails-plugin'
23+
license {
24+
name = 'Apache-2.0'
25+
}
26+
title = "Elasticserach"
27+
desc = "An Elasticsearch plugin for Grails"
28+
developers = [noam: 'Noam Y. Tenne', marcos: 'Marcos Carceles', puneet: 'Puneet Behl', james: 'James Kleeh']
1929
}
2030
}
2131

gradle/wrapper/gradle-wrapper.jar

2 Bytes
Binary file not shown.

gradlew.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ echo location of your Java installation.
4646
goto fail
4747

4848
:init
49-
@rem Get command-line arguments, handling Windowz variants
49+
@rem Get command-line arguments, handling Windows variants
5050

5151
if not "%OS%" == "Windows_NT" goto win9xME_args
5252
if "%@eval[2+2]" == "4" goto 4NT_args

grails-app/conf/application.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ environments:
9292
transport.sniff: true
9393
datastoreImpl: hibernateDatastore
9494
index:
95-
store.type: memory
95+
store.type: simplefs
9696
analysis:
9797
filter:
9898
replace_synonyms:
@@ -105,7 +105,6 @@ environments:
105105
repl_analyzer:
106106
tokenizer: standard
107107
filter: ['lowercase', 'replace_synonyms']
108-
109108
production:
110109
elasticSearch:
111110
client:

grails-app/conf/plugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ environments {
102102
test {
103103
elasticSearch {
104104
client.mode = 'local'
105-
index.store.type = 'memory' // store local node in memory and not on disk
105+
index.store.type = 'simplefs' // store local node in memory and not on disk
106106
}
107107
}
108108
production {

grails-app/domain/test/upperCase/UpperCase.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package test.upperCase
22

33
class UpperCase {
4-
def name;
4+
String name
55
static mapping = {
66

77
autoImport(false)

grails-app/services/grails/plugins/elasticsearch/ElasticSearchAdminService.groovy

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse
77
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest
88
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder
99
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest
10-
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest
1110
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest
12-
import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse
11+
import org.elasticsearch.action.support.broadcast.BroadcastResponse
1312
import org.elasticsearch.client.Client
1413
import org.elasticsearch.client.Requests
14+
import org.elasticsearch.cluster.health.ClusterHealthStatus
1515
import org.slf4j.Logger
1616
import org.slf4j.LoggerFactory
1717

@@ -44,7 +44,7 @@ class ElasticSearchAdminService {
4444

4545
// Refresh ES
4646
elasticSearchHelper.withElasticSearch { Client client ->
47-
BroadcastOperationResponse response
47+
BroadcastResponse response
4848
if (!indices) {
4949
response = client.admin().indices().refresh(Requests.refreshRequest()).actionGet()
5050
} else {
@@ -135,21 +135,6 @@ class ElasticSearchAdminService {
135135
}
136136
}
137137

138-
/**
139-
* Deletes a mapping on an index
140-
* @param index The index the mapping will be deleted on
141-
* @param type The type which mapping will be deleted
142-
*/
143-
void deleteMapping(String index, String type) {
144-
log.info("Deleting Elasticsearch mapping for ${index} and type ${type} ...")
145-
elasticSearchHelper.withElasticSearch { Client client ->
146-
client.admin().indices().deleteMapping(
147-
new DeleteMappingRequest(index).
148-
types(type)
149-
).actionGet()
150-
}
151-
}
152-
153138
/**
154139
* Creates mappings on a type
155140
* @param index The index where the mapping is being created
@@ -168,7 +153,7 @@ class ElasticSearchAdminService {
168153
}
169154

170155
/**
171-
* Check whether a mpping exists
156+
* Check whether a mapping exists
172157
* @param index The name of the index to check on
173158
* @param type The type which mapping is being checked
174159
* @return true if the mapping exists
@@ -197,14 +182,17 @@ class ElasticSearchAdminService {
197182
* @param index The name of the index
198183
* @param settings The index settings (ie. number of shards)
199184
*/
200-
void createIndex(String index, Map settings=null) {
185+
void createIndex(String index, Map settings=null, Map<String, Map> esMappings = [:]) {
201186
LOG.debug "Creating index ${index} ..."
202187

203188
elasticSearchHelper.withElasticSearch { Client client ->
204189
CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(index)
205190
if (settings) {
206191
builder.setSettings(settings)
207192
}
193+
esMappings.each { String type, Map elasticMapping ->
194+
builder.addMapping(type, elasticMapping)
195+
}
208196
builder.execute().actionGet()
209197
}
210198
}
@@ -215,9 +203,9 @@ class ElasticSearchAdminService {
215203
* @param version the version number, if provided <index>_v<version> will be used
216204
* @param settings The index settings (ie. number of shards)
217205
*/
218-
void createIndex(String index, Integer version, Map settings=null) {
206+
void createIndex(String index, Integer version, Map settings=null, Map<String, Map> esMappings = [:]) {
219207
index = versionIndex(index, version)
220-
createIndex(index, settings)
208+
createIndex(index, settings, esMappings)
221209
}
222210

223211
/**
@@ -254,7 +242,7 @@ class ElasticSearchAdminService {
254242
String indexPointedBy(String alias) {
255243
elasticSearchHelper.withElasticSearch { Client client ->
256244
def index = client.admin().indices().getAliases(new GetAliasesRequest().aliases([alias] as String[])).actionGet().getAliases()?.find {
257-
it.value.element.alias() == alias
245+
alias in it.value*.alias()
258246
}?.key
259247
if (!index) {
260248
LOG.debug("Alias ${alias} does not exist")
@@ -363,32 +351,12 @@ class ElasticSearchAdminService {
363351
getLatestVersion(index) + 1
364352
}
365353

366-
/**
367-
* Waits for an index to be on Yellow status
368-
* @param index
369-
* @return
370-
*/
371-
def waitForIndex(index) {
372-
elasticSearchHelper.withElasticSearch { Client client ->
373-
try {
374-
LOG.debug("Waiting at least yellow status on ${index}")
375-
client.admin().cluster().prepareHealth(index)
376-
.setWaitForYellowStatus()
377-
.execute().actionGet()
378-
} catch (Exception e) {
379-
// ignore any exceptions due to non-existing index.
380-
LOG.debug('Index health', e)
381-
}
382-
}
383-
}
384-
385354
/**
386355
* Waits for the cluster to be on Yellow status
387356
*/
388-
void waitForClusterYellowStatus() {
357+
void waitForClusterStatus(ClusterHealthStatus status=ClusterHealthStatus.YELLOW) {
389358
elasticSearchHelper.withElasticSearch { Client client ->
390-
ClusterHealthResponse response = client.admin().cluster().health(
391-
new ClusterHealthRequest([] as String[]).waitForYellowStatus()).actionGet()
359+
ClusterHealthResponse response = client.admin().cluster().health(new ClusterHealthRequest([] as String[]).waitForStatus(status)).actionGet()
392360
LOG.debug("Cluster status: ${response.status}")
393361
}
394362
}

grails-app/services/grails/plugins/elasticsearch/ElasticSearchService.groovy

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import org.elasticsearch.action.search.SearchRequest
2525
import org.elasticsearch.action.search.SearchType
2626
import org.elasticsearch.action.support.QuerySourceBuilder
2727
import org.elasticsearch.client.Client
28-
import org.elasticsearch.index.query.FilterBuilder
2928
import org.elasticsearch.index.query.QueryBuilder
3029
import org.elasticsearch.index.query.QueryStringQueryBuilder
3130
import org.elasticsearch.search.SearchHit
@@ -36,7 +35,7 @@ import org.elasticsearch.search.sort.SortOrder
3635
import org.slf4j.Logger
3736
import org.slf4j.LoggerFactory
3837

39-
import static org.elasticsearch.index.query.QueryBuilders.queryString
38+
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery
4039
import static org.elasticsearch.index.query.QueryStringQueryBuilder.Operator
4140

4241
class ElasticSearchService implements GrailsApplicationAware {
@@ -337,7 +336,7 @@ class ElasticSearchService implements GrailsApplicationAware {
337336
request.source(new GXContentBuilder().buildAsBytes(query))
338337
} else {
339338
Operator defaultOperator = params['default_operator'] ?: Operator.AND
340-
QueryStringQueryBuilder builder = queryString(query).defaultOperator(defaultOperator)
339+
QueryStringQueryBuilder builder = queryStringQuery(query).defaultOperator(defaultOperator)
341340
if (params.analyzer) {
342341
builder.analyzer(params.analyzer)
343342
}
@@ -352,7 +351,7 @@ class ElasticSearchService implements GrailsApplicationAware {
352351
*
353352
* @param params The query parameters
354353
* @param query The search query, whether a String, a Closure or a QueryBuilder
355-
* @param filter The search filter, whether a Closure or a FilterBuilder
354+
* @param filter The search filter, whether a Closure or a QueryBuilder
356355
* @return The SearchRequest instance
357356
*/
358357
private SearchRequest buildSearchRequest(query, filter, Map params) {
@@ -405,7 +404,7 @@ class ElasticSearchService implements GrailsApplicationAware {
405404

406405
SearchSourceBuilder setQueryInSource(SearchSourceBuilder source, String query, Map params = [:]) {
407406
Operator defaultOperator = params['default_operator'] ?: Operator.AND
408-
QueryStringQueryBuilder builder = queryString(query).defaultOperator(defaultOperator)
407+
QueryStringQueryBuilder builder = queryStringQuery(query).defaultOperator(defaultOperator)
409408
if (params.analyzer) {
410409
builder.analyzer(params.analyzer)
411410
}
@@ -424,7 +423,7 @@ class ElasticSearchService implements GrailsApplicationAware {
424423
source.postFilter(new GXContentBuilder().buildAsBytes(filter))
425424
}
426425

427-
SearchSourceBuilder setFilterInSource(SearchSourceBuilder source, FilterBuilder filter, Map params = [:]){
426+
SearchSourceBuilder setFilterInSource(SearchSourceBuilder source, QueryBuilder filter, Map params = [:]){
428427
source.postFilter(filter)
429428
}
430429

src/docs/introduction/acknowledgements.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Many thanks to all the users who reported issues and sent me pull requests.
88
* https://github.com/stefanrother[Stefan Rother-Stübs (Dating Cafe)]
99
* https://github.com/skies[Sven Kiesewetter (Dating Cafe)]
1010
* Michael Schwartz (Dating Cafe)
11+
* https://github.com/marcoscarceles[Marcos Carceles]
1112
* https://github.com/puneetbehl[Puneet Behl]
1213
1314
#### Authors and Contributors of the original plugin

src/docs/introduction/history.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
==== Grails 3.x version
44

5+
* June 3, 2016
6+
** 1.2.0
7+
*** Upgraded to Elasticsearch 2.3.3
8+
**** Support for `elasticsearch-groovy` client removed (no available compatible version, pending on https://github.com/elastic/elasticsearch-groovy/issues/35[Issue 35])
9+
**** `delete` migration strategy has been replaced by `deleteIndex`, due to new Elasticsearch 2.x API's
10+
*** Removed test classes from plugin distribution
11+
512
* April 18, 2016
613
** 1.0.0.1
714
*** Add ability to change search method name in domain class via config

0 commit comments

Comments
 (0)