# Rails and ElasticSearch. How to create 2 indices with one model?

**URL:** <https://discuss.elastic.co/t/rails-and-elasticsearch-how-to-create-2-indices-with-one-model/22453>\
**Category:** Elasticsearch\
**Created:** [March 1, 2015, 12:34am UTC](https://discuss.elastic.co/t/rails-and-elasticsearch-how-to-create-2-indices-with-one-model/22453 "2015-03-01T00:34:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuckYou](https://avatars.discourse-cdn.com/v4/letter/f/71c47a/32.png) [@fuckYou](https://discuss.elastic.co/u/fuckYou)\
**Post date:** [March 1, 2015, 12:34am UTC](https://discuss.elastic.co/t/rails-and-elasticsearch-how-to-create-2-indices-with-one-model/22453/1 "2015-03-01T00:34:29Z")

</div>

Hi,

Sorry for snuking into your group but I am compltely stuck with  
ElasticSearch and I need help 🙂

I am developping with ROR and the ES Gem.

class Post \< ActiveRecord::Base  
include Elasticsearch::Model  
include Elasticsearch::Model::Callbacks

_Here is my ROR model, anyway..._

```
def self.search(query)
      __elasticsearch__.search(

```

How can I specify wich index I want this function to search in ??  
{  
query:  
here is a complex query  
}  
)  
end

```
  index_name "index_post_search" (I need another index...how can I do 

```

?)

```
  settings index_post_search: { number_of_shards: 1 } do How can I and 

```

another setting to this model ?  
mappings dynamic: 'false' do  
indexes :title, analyzer: 'english', index\_options:  
'offsets'  
indexes :content, analyzer: 'english'  
end  
end  
end

How can I create and update another index ?

Post. **elasticsearch**.client.indices.delete index: "index\_post\_search"  
rescue nil  
Post. **elasticsearch**.client.indices.create index: "index\_post\_search",  
body: { settings: Post.settings.to\_hash, mappings: Post.mappings.to\_hash }  
Post.import

Thk U for your attention !!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/62b8c4e5-7fb8-4e85-b286-6e91cb36ffe6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/62b8c4e5-7fb8-4e85-b286-6e91cb36ffe6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:29am UTC](https://discuss.elastic.co/t/rails-and-elasticsearch-how-to-create-2-indices-with-one-model/22453/2 "2017-07-06T00:29:15Z")

</div>

Closed on July 6, 2017, 12:29am UTC


