我是Elasticsearch的新手,并且正在使用复活的grails插件"elasticsearch:0.0.4.6“。
我想通过用户的firstName、姓氏或用户名来实现对用户的搜索,这将返回完整的域实例。我有两个域类:
用户:
class User {
String firstName
String surname
static hasOne = [profile:Profile]
static hasMany = [friends:User]
static mappedBy = [ friends: 'friends' ]
static searchable = {
profile component:true
only = ['firstName', 'surname', 'profile']
}
...配置文件:
class Profile {
String username
String status
byte[] photo
static belongsTo = [user:User]
static searchable = true
...
}我创建了类"searchable = true“,然后创建了以下搜索:
def res = User.search("${params.friendSearch}").searchResults这找到了正确的实例,但是现在当用户将照片添加到他们的配置文件时,它成功了,但是我收到了以下错误的永无休止的循环:
ERROR index.IndexRequestQueue -失败的大容量项:MapperParsingException[未能解析照片];嵌套: NumberFor matException[用于输入字符串: the photos base64inputstring
我真的不明白发生了什么,但我想这肯定与elasticsearch无法索引照片数据有关。有人能解释一下吗?
然后我试验了可搜索的自定义映射选项-
等
什么都没用。最后我加入了
它阻止了错误的发生,并允许我根据上面提到的标准找到用户。但是,由于“只有”限制,这意味着seach返回的用户实例有一个相等于null的照片属性,但是我需要这个值!
我做错什么了?有谁能建议我采取什么最好的行动方针或者我对Elasticsearch有什么误解吗?谢谢
发布于 2016-06-26 06:12:18
我认为您可能必须将字节属性照片排除在可搜索字段中,如下所示:
class Profile {
String username
String status
byte[] photo
static belongsTo = [user:User]
static searchable = {
except = ['photo']
}这将排除属性照片的索引和搜索。因此,将字节格式转换为字符串格式的输出不会失败。
另外,也许您可能需要一个自定义转换器来将字节(字符串)更改为更有用的结果?
https://stackoverflow.com/questions/35978231
复制相似问题