Skip to content

Commit

Permalink
Merge pull request #158 from Endource/elasticsearch-2.3
Browse files Browse the repository at this point in the history
Elasticsearch 2.3
  • Loading branch information
puneetbehl authored Jun 21, 2016
2 parents 92a40da + a8d55c7 commit 4f9a446
Show file tree
Hide file tree
Showing 36 changed files with 580 additions and 401 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ plugin.xml
.project
test/reports
data/

#Elasticserch plugin binaries
src/integration-test/resources/elasticsearch/plugins
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: groovy
jdk:
- oraclejdk7
- oraclejdk8
before_script:
- rm -rf target
script: travis_wait 60 ./travis-build.sh
Expand Down
25 changes: 24 additions & 1 deletion README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,35 @@ Edit your project's +build.gradle+ file, by adding the plugin's dependency decla
----
dependencies {
...
compile "org.grails.plugins:elasticsearch:1.0.0.2"
compile "org.grails.plugins:elasticsearch:2.3.0"
...
}
----


=== Versioning

|===
|Plugin Version | Grails Version | Elasticsearch Version

|2.3.x
|3.y
|2.3.z

|1.0.0.x
|3.y
|1.6.z

|0.1.0.x
|2.y
|2.1.z

|0.0.4.x
|2.y
|1.6.z
|===

=== Ohs Nos! I'm hitting a +java.lang.Exception: No datastore implementation specified+

This error means that you probably haven't specified your datastore type in your +application.groovy+ or +application.yml+ file.
Expand Down
17 changes: 9 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
id "com.jfrog.bintray" version "1.2"
}

version "1.0.0.2"
version "1.2.0"
group "org.grails.plugins"

apply plugin: 'maven-publish'
Expand All @@ -30,11 +30,11 @@ apply plugin: "org.grails.grails-gsp"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
elasticsearchVersion = "1.0.0.3"
elasticsearchVersion = "2.3.3"
}

sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenLocal()
Expand Down Expand Up @@ -64,6 +64,8 @@ sourcesJar {
exclude "test/**/**"
}

def elasticsearchVersion = '2.3.3'

dependencies {
provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
Expand All @@ -77,17 +79,16 @@ dependencies {
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"

testRuntime('org.elasticsearch:elasticsearch-groovy:1.6.0') {
exclude module: 'groovy-all'
}
compile "org.elasticsearch:elasticsearch-mapper-attachments:2.6.0"
compile "org.elasticsearch:elasticsearch:${elasticsearchVersion}"

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

console "org.grails:grails-console"

compile "org.elasticsearch.plugin:mapper-attachments:${elasticsearchVersion}"
}

task wrapper(type: Wrapper) {
Expand Down
12 changes: 11 additions & 1 deletion gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ if (bintrayProperties.exists()) {
}
title = "Elasticserach"
desc = "An Elasticsearch plugin for Grails"
developers = [noam: 'Noam Y. Tenne', macrcos: 'Marcos Carceles', puneet: 'Puneet Behl', james: 'James Kleeh']
developers = [noam: 'Noam Y. Tenne', marcos: 'Marcos Carceles', puneet: 'Puneet Behl', james: 'James Kleeh']
}
} else {
grailsPublish {
githubSlug = 'noamt/elasticsearch-grails-plugin'
license {
name = 'Apache-2.0'
}
title = "Elasticserach"
desc = "An Elasticsearch plugin for Grails"
developers = [noam: 'Noam Y. Tenne', marcos: 'Marcos Carceles', puneet: 'Puneet Behl', james: 'James Kleeh']
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
Expand Down
3 changes: 1 addition & 2 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ environments:
transport.sniff: true
datastoreImpl: hibernateDatastore
index:
store.type: memory
store.type: simplefs
analysis:
filter:
replace_synonyms:
Expand All @@ -105,7 +105,6 @@ environments:
repl_analyzer:
tokenizer: standard
filter: ['lowercase', 'replace_synonyms']

production:
elasticSearch:
client:
Expand Down
2 changes: 1 addition & 1 deletion grails-app/conf/plugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ environments {
test {
elasticSearch {
client.mode = 'local'
index.store.type = 'memory' // store local node in memory and not on disk
index.store.type = 'simplefs' // store local node in memory and not on disk
}
}
production {
Expand Down
2 changes: 1 addition & 1 deletion grails-app/domain/test/upperCase/UpperCase.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package test.upperCase

class UpperCase {
def name;
String name
static mapping = {

autoImport(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest
import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse
import org.elasticsearch.action.support.broadcast.BroadcastResponse
import org.elasticsearch.client.Client
import org.elasticsearch.client.Requests
import org.elasticsearch.cluster.health.ClusterHealthStatus
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -44,7 +44,7 @@ class ElasticSearchAdminService {

// Refresh ES
elasticSearchHelper.withElasticSearch { Client client ->
BroadcastOperationResponse response
BroadcastResponse response
if (!indices) {
response = client.admin().indices().refresh(Requests.refreshRequest()).actionGet()
} else {
Expand Down Expand Up @@ -135,21 +135,6 @@ class ElasticSearchAdminService {
}
}

/**
* Deletes a mapping on an index
* @param index The index the mapping will be deleted on
* @param type The type which mapping will be deleted
*/
void deleteMapping(String index, String type) {
log.info("Deleting Elasticsearch mapping for ${index} and type ${type} ...")
elasticSearchHelper.withElasticSearch { Client client ->
client.admin().indices().deleteMapping(
new DeleteMappingRequest(index).
types(type)
).actionGet()
}
}

/**
* Creates mappings on a type
* @param index The index where the mapping is being created
Expand All @@ -168,7 +153,7 @@ class ElasticSearchAdminService {
}

/**
* Check whether a mpping exists
* Check whether a mapping exists
* @param index The name of the index to check on
* @param type The type which mapping is being checked
* @return true if the mapping exists
Expand Down Expand Up @@ -197,14 +182,17 @@ class ElasticSearchAdminService {
* @param index The name of the index
* @param settings The index settings (ie. number of shards)
*/
void createIndex(String index, Map settings=null) {
void createIndex(String index, Map settings=null, Map<String, Map> esMappings = [:]) {
LOG.debug "Creating index ${index} ..."

elasticSearchHelper.withElasticSearch { Client client ->
CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(index)
if (settings) {
builder.setSettings(settings)
}
esMappings.each { String type, Map elasticMapping ->
builder.addMapping(type, elasticMapping)
}
builder.execute().actionGet()
}
}
Expand All @@ -215,9 +203,9 @@ class ElasticSearchAdminService {
* @param version the version number, if provided <index>_v<version> will be used
* @param settings The index settings (ie. number of shards)
*/
void createIndex(String index, Integer version, Map settings=null) {
void createIndex(String index, Integer version, Map settings=null, Map<String, Map> esMappings = [:]) {
index = versionIndex(index, version)
createIndex(index, settings)
createIndex(index, settings, esMappings)
}

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

/**
* Waits for an index to be on Yellow status
* @param index
* @return
*/
def waitForIndex(index) {
elasticSearchHelper.withElasticSearch { Client client ->
try {
LOG.debug("Waiting at least yellow status on ${index}")
client.admin().cluster().prepareHealth(index)
.setWaitForYellowStatus()
.execute().actionGet()
} catch (Exception e) {
// ignore any exceptions due to non-existing index.
LOG.debug('Index health', e)
}
}
}

/**
* Waits for the cluster to be on Yellow status
*/
void waitForClusterYellowStatus() {
void waitForClusterStatus(ClusterHealthStatus status=ClusterHealthStatus.YELLOW) {
elasticSearchHelper.withElasticSearch { Client client ->
ClusterHealthResponse response = client.admin().cluster().health(
new ClusterHealthRequest([] as String[]).waitForYellowStatus()).actionGet()
ClusterHealthResponse response = client.admin().cluster().health(new ClusterHealthRequest([] as String[]).waitForStatus(status)).actionGet()
LOG.debug("Cluster status: ${response.status}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.elasticsearch.action.search.SearchRequest
import org.elasticsearch.action.search.SearchType
import org.elasticsearch.action.support.QuerySourceBuilder
import org.elasticsearch.client.Client
import org.elasticsearch.index.query.FilterBuilder
import org.elasticsearch.index.query.QueryBuilder
import org.elasticsearch.index.query.QueryStringQueryBuilder
import org.elasticsearch.search.SearchHit
Expand All @@ -36,7 +35,7 @@ import org.elasticsearch.search.sort.SortOrder
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import static org.elasticsearch.index.query.QueryBuilders.queryString
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery
import static org.elasticsearch.index.query.QueryStringQueryBuilder.Operator

class ElasticSearchService implements GrailsApplicationAware {
Expand Down Expand Up @@ -337,7 +336,7 @@ class ElasticSearchService implements GrailsApplicationAware {
request.source(new GXContentBuilder().buildAsBytes(query))
} else {
Operator defaultOperator = params['default_operator'] ?: Operator.AND
QueryStringQueryBuilder builder = queryString(query).defaultOperator(defaultOperator)
QueryStringQueryBuilder builder = queryStringQuery(query).defaultOperator(defaultOperator)
if (params.analyzer) {
builder.analyzer(params.analyzer)
}
Expand All @@ -352,7 +351,7 @@ class ElasticSearchService implements GrailsApplicationAware {
*
* @param params The query parameters
* @param query The search query, whether a String, a Closure or a QueryBuilder
* @param filter The search filter, whether a Closure or a FilterBuilder
* @param filter The search filter, whether a Closure or a QueryBuilder
* @return The SearchRequest instance
*/
private SearchRequest buildSearchRequest(query, filter, Map params) {
Expand Down Expand Up @@ -405,7 +404,7 @@ class ElasticSearchService implements GrailsApplicationAware {

SearchSourceBuilder setQueryInSource(SearchSourceBuilder source, String query, Map params = [:]) {
Operator defaultOperator = params['default_operator'] ?: Operator.AND
QueryStringQueryBuilder builder = queryString(query).defaultOperator(defaultOperator)
QueryStringQueryBuilder builder = queryStringQuery(query).defaultOperator(defaultOperator)
if (params.analyzer) {
builder.analyzer(params.analyzer)
}
Expand All @@ -424,7 +423,7 @@ class ElasticSearchService implements GrailsApplicationAware {
source.postFilter(new GXContentBuilder().buildAsBytes(filter))
}

SearchSourceBuilder setFilterInSource(SearchSourceBuilder source, FilterBuilder filter, Map params = [:]){
SearchSourceBuilder setFilterInSource(SearchSourceBuilder source, QueryBuilder filter, Map params = [:]){
source.postFilter(filter)
}

Expand Down
1 change: 1 addition & 0 deletions src/docs/introduction/acknowledgements.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Many thanks to all the users who reported issues and sent me pull requests.
* https://github.com/stefanrother[Stefan Rother-Stübs (Dating Cafe)]
* https://github.com/skies[Sven Kiesewetter (Dating Cafe)]
* Michael Schwartz (Dating Cafe)
* https://github.com/marcoscarceles[Marcos Carceles]
* https://github.com/puneetbehl[Puneet Behl]
#### Authors and Contributors of the original plugin
Expand Down
7 changes: 7 additions & 0 deletions src/docs/introduction/history.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

==== Grails 3.x version

* June 3, 2016
** 1.2.0
*** Upgraded to Elasticsearch 2.3.3
**** Support for `elasticsearch-groovy` client removed (no available compatible version, pending on https://github.com/elastic/elasticsearch-groovy/issues/35[Issue 35])
**** `delete` migration strategy has been replaced by `deleteIndex`, due to new Elasticsearch 2.x API's
*** Removed test classes from plugin distribution

* April 18, 2016
** 1.0.0.1
*** Add ability to change search method name in domain class via config
Expand Down
Loading

0 comments on commit 4f9a446

Please sign in to comment.