Skip to content

Commit 55692b7

Browse files
authored
fixes #172 (#204)
* grails/elasticsearch-grails-plugin/issues#169 fix for slow mongodb pagination query * grails/elasticsearch-grails-plugin/issues#170 fix for mapping string field to `keyword` ES type * grails/elasticsearch-grails-plugin/issues#170 fix for mapping string field to `keyword` ES type fixed github actions syntax * rolling back ALA specific changes disabled spring MongoClient autoconfiguration
1 parent 00a8891 commit 55692b7

File tree

7 files changed

+25
-6
lines changed

7 files changed

+25
-6
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ jobs:
7878
FOLDER: build/docs/manual
7979
DOC_FOLDER: gh-pages
8080
COMMIT_EMAIL: behlp@objectcomputing.com
81-
COMMIT_NAME: Puneet Behl
81+
COMMIT_NAME: Puneet Behl

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
buildscript {
22
repositories {
3+
mavenLocal ()
34
maven { url "https://repo.grails.org/grails/core" }
45
}
56
dependencies {
@@ -73,6 +74,7 @@ dependencies {
7374
compile "org.elasticsearch:elasticsearch:${elasticsearchVersion}"
7475
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-client', version: elasticsearchVersion
7576
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: elasticsearchVersion
77+
compile "org.mongodb:mongodb-driver:3.9.1"
7678
compile group: 'org.locationtech.spatial4j', name: 'spatial4j', version: '0.8'
7779

7880
console "org.grails:grails-console"
@@ -83,6 +85,7 @@ dependencies {
8385
testRuntime 'org.apache.tomcat:tomcat-jdbc'
8486

8587
testCompile "org.grails:grails-gorm-testing-support"
88+
// testCompile "org.grails:grails-plugin-testing"
8689
testCompile "org.grails:grails-web-testing-support"
8790

8891
testCompile 'com.vividsolutions:jts:1.13'

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ projectVersion=3.0.2-SNAPSHOT
22
grailsVersion=4.1.0
33
grailsGradlePluginVersion=4.1.0
44
gormHibernateVersion=7.0.5
5-
elasticsearchVersion=7.8.0
5+
elasticsearchVersion=7.8.1
66

77
org.gradle.caching=true
88
org.gradle.daemon=true

gradle/publish.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ githubPages {
1818
}
1919
}
2020

21-
task publishDocs(dependsOn: [docs, publishGhPages])
21+
task publishDocs(dependsOn: [docs, publishGhPages])

grails-app/conf/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ spring:
3232
- grails-app/views/**
3333
- grails-app/i18n/**
3434
- grails-app/conf/**
35+
autoconfigure:
36+
exclude:
37+
- org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
3538
management:
3639
endpoints:
3740
enabled-by-default: false

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import grails.plugins.elasticsearch.index.IndexRequestQueue
2222
import grails.plugins.elasticsearch.mapping.SearchableClassMapping
2323
import grails.plugins.elasticsearch.util.GXContentBuilder
2424
import groovy.util.logging.Slf4j
25+
import org.bson.types.MinKey
2526
import org.elasticsearch.action.search.SearchRequest
2627
import org.elasticsearch.action.search.SearchResponse
2728
import org.elasticsearch.client.RequestOptions
@@ -58,6 +59,7 @@ class ElasticSearchService implements GrailsApplicationAware {
5859

5960
private static final int INDEX_REQUEST = 0
6061
private static final int DELETE_REQUEST = 1
62+
static final String MONGO_DATABASE = "mongoDatastore"
6163

6264
GrailsApplication grailsApplication
6365
ElasticSearchHelper elasticSearchHelper
@@ -352,13 +354,24 @@ class ElasticSearchService implements GrailsApplicationAware {
352354
}
353355
}*/
354356
long offset = 0L
357+
def id = new MinKey()
355358
(1..rounds).each { round ->
356359
try {
357360
log.debug("Bulk index iteration $round: fetching $max results starting from ${offset}")
358361
persistenceInterceptor.init()
359362
persistenceInterceptor.setReadOnly()
360363

361-
List<Class<?>> results = domainClass.listOrderById([offset: offset, max: max, readOnly: true, sort: 'id', order: "asc"])
364+
List<Class<?>> results
365+
switch (grailsApplication.config.elasticsearch.datastoreImpl) {
366+
case MONGO_DATABASE:
367+
results = domainClass.createCriteria().list([offset: 0, max: max, readOnly: true, sort: 'id', order: "asc"]) {
368+
gt 'id', id
369+
}
370+
break
371+
default:
372+
results = domainClass.listOrderById([offset: offset, max: max, readOnly: true, sort: 'id', order: "asc"])
373+
break
374+
}
362375

363376
// set lastId for next run
364377
offset = round * max
@@ -372,6 +385,7 @@ class ElasticSearchService implements GrailsApplicationAware {
372385
indexRequestQueue.addDeleteRequest(entry)
373386
log.debug("Adding the document ${entry.id} to the delete request queue")
374387
}
388+
id = entry.id
375389
}
376390
indexRequestQueue.executeRequests()
377391

src/main/groovy/grails/plugins/elasticsearch/mapping/SearchableClassPropertyMapping.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ class SearchableClassPropertyMapping {
207207
* @return true if field is analyzed. NOTE it doesn't have to be stored.
208208
*/
209209
boolean isAnalyzed() {
210-
String index = (String) mappingAttributes.index
211-
(index == null || index)
210+
mappingAttributes.get('index') != null ? mappingAttributes.get('index') == 'false' : true
212211
}
213212

214213
/**

0 commit comments

Comments
 (0)