I have a Post model:
class Post < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
# I WANT THIS FUNCTION EXECUTED ON index1
def self.search1(query)
__elasticsearch__.search(
{
query:
}
)
end
# I WANT THIS FUNCTION EXECUTED ON index2
def self.search2(query)
__elasticsearch__.search(
{
query:
}
)
end
index_name "index1"
# I NEED ANOTHER INDEX ? HOW CAN I DO ?
settings index1: { number_of_shards: 1 } do
mappings dynamic: 'false' do
indexes :title, analyzer: 'english'
end
end
end
Post.__elasticsearch__.client.indices.delete index: "index1" rescue nil
Post.__elasticsearch__.client.indices.create index: "index1", body: { settings: Post.settings.to_hash, mappings: Post.mappings.to_hash }
Post.import
I have 1 model, 2 very different functions which need a completely different index.
How can I build 2 different indices in 1 model and tell the __elasticsearch__.search which index it should use ?