Skip to content

Commit

Permalink
fixes #172 (#204)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
temi committed Sep 19, 2024
1 parent 00a8891 commit 55692b7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ jobs:
FOLDER: build/docs/manual
DOC_FOLDER: gh-pages
COMMIT_EMAIL: [email protected]
COMMIT_NAME: Puneet Behl
COMMIT_NAME: Puneet Behl
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
buildscript {
repositories {
mavenLocal ()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
Expand Down Expand Up @@ -73,6 +74,7 @@ dependencies {
compile "org.elasticsearch:elasticsearch:${elasticsearchVersion}"
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-client', version: elasticsearchVersion
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: elasticsearchVersion
compile "org.mongodb:mongodb-driver:3.9.1"
compile group: 'org.locationtech.spatial4j', name: 'spatial4j', version: '0.8'

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

testCompile "org.grails:grails-gorm-testing-support"
// testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails:grails-web-testing-support"

testCompile 'com.vividsolutions:jts:1.13'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ projectVersion=3.0.2-SNAPSHOT
grailsVersion=4.1.0
grailsGradlePluginVersion=4.1.0
gormHibernateVersion=7.0.5
elasticsearchVersion=7.8.0
elasticsearchVersion=7.8.1

org.gradle.caching=true
org.gradle.daemon=true
2 changes: 1 addition & 1 deletion gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ githubPages {
}
}

task publishDocs(dependsOn: [docs, publishGhPages])
task publishDocs(dependsOn: [docs, publishGhPages])
3 changes: 3 additions & 0 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ spring:
- grails-app/views/**
- grails-app/i18n/**
- grails-app/conf/**
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
management:
endpoints:
enabled-by-default: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import grails.plugins.elasticsearch.index.IndexRequestQueue
import grails.plugins.elasticsearch.mapping.SearchableClassMapping
import grails.plugins.elasticsearch.util.GXContentBuilder
import groovy.util.logging.Slf4j
import org.bson.types.MinKey
import org.elasticsearch.action.search.SearchRequest
import org.elasticsearch.action.search.SearchResponse
import org.elasticsearch.client.RequestOptions
Expand Down Expand Up @@ -58,6 +59,7 @@ class ElasticSearchService implements GrailsApplicationAware {

private static final int INDEX_REQUEST = 0
private static final int DELETE_REQUEST = 1
static final String MONGO_DATABASE = "mongoDatastore"

GrailsApplication grailsApplication
ElasticSearchHelper elasticSearchHelper
Expand Down Expand Up @@ -352,13 +354,24 @@ class ElasticSearchService implements GrailsApplicationAware {
}
}*/
long offset = 0L
def id = new MinKey()
(1..rounds).each { round ->
try {
log.debug("Bulk index iteration $round: fetching $max results starting from ${offset}")
persistenceInterceptor.init()
persistenceInterceptor.setReadOnly()

List<Class<?>> results = domainClass.listOrderById([offset: offset, max: max, readOnly: true, sort: 'id', order: "asc"])
List<Class<?>> results
switch (grailsApplication.config.elasticsearch.datastoreImpl) {
case MONGO_DATABASE:
results = domainClass.createCriteria().list([offset: 0, max: max, readOnly: true, sort: 'id', order: "asc"]) {
gt 'id', id
}
break
default:
results = domainClass.listOrderById([offset: offset, max: max, readOnly: true, sort: 'id', order: "asc"])
break
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ class SearchableClassPropertyMapping {
* @return true if field is analyzed. NOTE it doesn't have to be stored.
*/
boolean isAnalyzed() {
String index = (String) mappingAttributes.index
(index == null || index)
mappingAttributes.get('index') != null ? mappingAttributes.get('index') == 'false' : true
}

/**
Expand Down

0 comments on commit 55692b7

Please sign in to comment.