私はすでにこの問題についていくつかのスレッドを見てきましたが、誰も救うことができませんでした。私の DomainClass には次のものがあります
def afterInsert() {
elasticSearchService.index(this)
}
Elasticsaerch はサービスであり、静的一時リストに追加しました。index メソッドを正常に呼び出した後、この例外がスローされるようです
Message: null id in com.easytha.Student entry (don't flush the Session after an exception occurs)
これは index メソッドのコードです
def index(object) {
try {
if(object==null) {
throw new NullPointerException()
}
if(!(object instanceof Collection || object instanceof Object[])) {
IndexResponse response = client.prepareIndex(grailsApplication.config.esIndexName, object.getClass().getName(),object.id.toString())
.setSource((object as JSON).toString() )
.execute().actionGet()
println "object indexed successfully"
}else if(object instanceof Collection || object instanceof Object[]) {
for (var in object) {
index(var)
}
}
}catch(e) {
e.printStackTrace();
}
}
「object indexed successfully」がコンソールに出力されます。
bootstrap.groovy には次のものがあります
Student student4 = new Student(firstName:'Sapan',lastName:'Parikh',email:'sapan.parikh@eclinicalworks.com',password:'test123')
student4.save(failOnError : true)
アップデート
私はどれがうまくいったか試しStudent.withNewSession { elasticSearchService.index(this) }
ました。