弹性搜索 Grails 中的解组域 class 错误
unmarshalling domain class error in elastic search Grails
我正在尝试在 Grails 3.1.6 中使用 ElasticSearch 1.0.0.2。
域名class是:
class Post {
String content
Date dateCreated
static belongsTo = [user: User]
static hasMany = [tags: Tag]
static searchable = {
tags component : true
user component: true
}
}
我在我的 SearchController 中注入了 ElasticSearchService 并尝试获取搜索结果:
try {
def searchResult = elasticSearchService.search("${params.q}")
// def searchResult = Post.search("${params.q}")
println("search result: "+searchResult)
return [searchResult: searchResult]
}catch (e){
println e.message
return [searchError: true]
}
但是出现这样的错误:
ERROR grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller - Error unmarshalling property 'user' of Class Post with id 4
java.lang.IllegalStateException: Property Post.user is not mapped as [component], but broken search hit found.
at sun.reflect.GeneratedConstructorAccessor116.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller.unmarshallProperty(DomainClassUnmarshaller.groovy:206)
at sun.reflect.GeneratedMethodAccessor339.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1432)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:64)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:190)
谁能告诉我我犯了什么错误。谢谢
有同样的问题,使用了 elastisearch 插件文档中的这篇文章将我的组件更改为引用,这解决了我的问题:
3.8.1。可搜索参考
searchable-reference 映射模式是用于关联的默认模式,并且要求关联的可搜索 class 为 root-mapped 才能拥有自己的索引。使用这种模式,关联的域不会在生成的 JSON 文档中完全编组:仅保留实例的 ID 和类型。当从索引中检索文档时,插件将使用存储的 id 自动从索引重建关联。
例子
class MyDomain {
// odom is an association with the OtherDomain class, set as a reference
OtherDomain odom
static searchable = {
odom reference:true
}
}
// The OtherDomain definition, with default searchable
class OtherDomain {
static searchable = true
String field1 = "val1"
String field2 = "val2"
String field3 = "val3"
String field4 = "val4"
}
索引 MyDomain 实例时,生成的 JSON 文档将发送到 ElasticSearch:
{
"mydomain": {
"_id":1,
"odom": { "id":1 }
}
}
{
"otherdomain": {
"_id":1,
"field1":"val1",
"field2":"val2",
"field3":"val3",
"field4":"val4"
}
}
这是文档的 link
http://noamt.github.io/elasticsearch-grails-plugin/docs/index.html#searchableComponentReference
我正在尝试在 Grails 3.1.6 中使用 ElasticSearch 1.0.0.2。
域名class是:
class Post {
String content
Date dateCreated
static belongsTo = [user: User]
static hasMany = [tags: Tag]
static searchable = {
tags component : true
user component: true
}
}
我在我的 SearchController 中注入了 ElasticSearchService 并尝试获取搜索结果:
try {
def searchResult = elasticSearchService.search("${params.q}")
// def searchResult = Post.search("${params.q}")
println("search result: "+searchResult)
return [searchResult: searchResult]
}catch (e){
println e.message
return [searchError: true]
}
但是出现这样的错误:
ERROR grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller - Error unmarshalling property 'user' of Class Post with id 4
java.lang.IllegalStateException: Property Post.user is not mapped as [component], but broken search hit found.
at sun.reflect.GeneratedConstructorAccessor116.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller.unmarshallProperty(DomainClassUnmarshaller.groovy:206)
at sun.reflect.GeneratedMethodAccessor339.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1432)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:64)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:190)
谁能告诉我我犯了什么错误。谢谢
有同样的问题,使用了 elastisearch 插件文档中的这篇文章将我的组件更改为引用,这解决了我的问题:
3.8.1。可搜索参考 searchable-reference 映射模式是用于关联的默认模式,并且要求关联的可搜索 class 为 root-mapped 才能拥有自己的索引。使用这种模式,关联的域不会在生成的 JSON 文档中完全编组:仅保留实例的 ID 和类型。当从索引中检索文档时,插件将使用存储的 id 自动从索引重建关联。
例子
class MyDomain {
// odom is an association with the OtherDomain class, set as a reference
OtherDomain odom
static searchable = {
odom reference:true
}
}
// The OtherDomain definition, with default searchable
class OtherDomain {
static searchable = true
String field1 = "val1"
String field2 = "val2"
String field3 = "val3"
String field4 = "val4"
}
索引 MyDomain 实例时,生成的 JSON 文档将发送到 ElasticSearch:
{
"mydomain": {
"_id":1,
"odom": { "id":1 }
}
}
{
"otherdomain": {
"_id":1,
"field1":"val1",
"field2":"val2",
"field3":"val3",
"field4":"val4"
}
}
这是文档的 link http://noamt.github.io/elasticsearch-grails-plugin/docs/index.html#searchableComponentReference