【问题标题】:Grails Elasticsearch plugin issuesGrails Elasticsearch 插件问题
【发布时间】:2016-06-28 22:36:26
【问题描述】:

我是 Elasticsearch 的新手,正在使用复兴的 grails 插件“elasticsearch:0.0.4.6”。

我想通过名字、姓氏或用户名实现对用户的搜索,这将返回完整的域实例。 我有 2 个域类:

用户:

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

这找到了正确的实例,但是现在当用户将照片添加到他们的个人资料时,它成功了,但我收到了以下错误的永无止境的循环:

错误 index.IndexRequestQueue - 批量项目失败:MapperParsingException[无法解析 [照片]];嵌套:NumberFor matException[对于输入字符串:照片base64输入字符串

我真的不明白发生了什么,但我认为这一定与 elasticsearch 无法索引照片数据有关。谁能解释一下?

然后我尝试了可搜索的自定义映射选项 -

  • 个人资料索引:'否'
  • 全部=假
  • excludeFromAll = true

没有任何效果。最后我加了

  • 仅 = ['用户名']

它阻止了错误的发生,并允许我根据上面提到的标准找到用户。但是,由于“唯一”的限制,这意味着 seach 返回的 User 实例有一个等于 null 的 photo 属性,但我需要这个值!

我做错了什么?谁能建议我采取的最佳行动方案或我对 Elasticsearch 的任何误解?谢谢

【问题讨论】:

    标签: grails elasticsearch grails-orm elasticsearch-plugin


    【解决方案1】:

    我认为您可能必须从可搜索字段中排除字节属性照片,如下所示:

    class Profile {
    
    String username
    String status
    byte[] photo
    
    static belongsTo = [user:User]
    
    static searchable = {
      except = ['photo']
    }
    

    这会将房产照片排除在索引和搜索之外。因此将字节格式转换为字符串格式的输出不会失败。

    也许您可能需要一个自定义转换器来将字节(字符串)更改为在结果中更有用的东西?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多