【问题标题】:ElasticSearch : Index the results of a method that has argumentsElasticSearch:索引具有参数的方法的结果
【发布时间】:2014-11-12 15:32:52
【问题描述】:

我正在开发一个 Rails 应用程序,它应该可以扩展到至少 10 万用户。但是,当我们在数据库中填充足够多的数据时,它会显着变慢,我们计划使用 ElasticSearch 作为解决方案。我的问题主要与我网站中的用户列表页面有关,其中特定功能是 CPU 密集型的,我们希望为该功能编制索引。

所以,这就是问题所在。这个函数有我们无法避免的参数,我还没有找到任何可以建议我如何将参数传递给索引函数的示例。

这是一个我觉得很有帮助的问题:Index the results of a method in ElasticSearch (Tire + ActiveRecord)

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 elasticsearch full-text-search


    【解决方案1】:

    你可以试着写这样的东西:

    def to_indexed_json
      { field: method(args) }.to_json
    end
    

    甚至没有to_indexed_json 你也可以写:

    mapping do
      indexes :field_name
    end
    
    def field_name
      your_method(args)
    end
    

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 2020-12-26
      • 2020-09-05
      • 2019-11-02
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      相关资源
      最近更新 更多