我正在使用 Elasticsearch 持久性模型,并且对每个索引都有一些通用的方法。
给定一个事件索引,我有一个服务类,其中定义了一些方法,其他 n 个由它们的模型构建的索引也是如此。
class EventSearchService
class << self
def with_index(index_name)
old_repository = repository
@repository = EventSearchService::ElasticsearchEventRepository.new(index_name: index_name)
yield
ensure
@repository = old_repository
end
def index_name
repository.index_name
end
def index_all(event_documents)
return unless event_documents.present?
actions = event_documents.map do |e|
{ index: { _index: index_name, _id: e.id, _type: "_doc", data: e.to_hash }}
end
repository.client.bulk(body: actions)
end
protected
def repository
@repository ||= EventSearchService::ElasticsearchEventRepository.new
end
end
end
Run Code Online (Sandbox Code Playgroud)
我的问题是我最终得到了 n 个具有相同类方法的文件。当我尝试将其直接提取到抽象类时,我收到一个错误,该错误的调查使我发现无法继承单例类。
搜索了一些答案后,我关注了这个线程,并尝试将其干燥
require 'forwardable'
require 'singleton'
class ElasticsearchService
include Singleton
class …Run Code Online (Sandbox Code Playgroud) 我对 Hadoop 非常陌生,并试图使用它运行一个简单的程序。
我已将本地示例数据复制到 hdfs,但在我的 map reduce 作业期间,当我按照官方 apache 文档运行此命令时
hadoop jar hadoop-streaming-2.7.3.jar \
-input /user/hduser/gutenberg/* \
-output /user/hduser/gutenberg-output \
-mapper /home/hduser/mapper.py \
-reducer /home/hduser/reducer.py
Run Code Online (Sandbox Code Playgroud)
我收到此错误
不是有效的 JAR:/usr/lib/hadoop-streaming-2.7.3.jar
请试着帮助我。
我是 Rails 的新手,并且已经看到了我的问题的所有可能的答案,因为其他开发人员经常问这个问题,但我无法解决它。请看一看。
当我尝试从控制台添加数据时出现此错误
User.create(name: "Michael Hartl", email: "mhartl@example.com", phone: "0123456789", password: "foobar", password_confirmation: "foobar")
Run Code Online (Sandbox Code Playgroud)
错误显示
undefined method `password_digest=' for #<User:0x0000000375c788>
Did you mean? password=
Run Code Online (Sandbox Code Playgroud)
控制器
def create
@candidate = User.new(user_params)
if @candidate.save
flash[:notice] = "New Candidate Added Successfully"
redirect_to(users_path)
else
render('new')
end
end
private
def user_params
#Whitelisting for strng parameters
params.require(:user).permit(:name, :email, :password, :password_confirmation, :qualification, :college, :stream, :phone)
end
Run Code Online (Sandbox Code Playgroud)
移民:
class CreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
t.string :name, null: false
t.boolean :admin_user, default: false
t.string …Run Code Online (Sandbox Code Playgroud)