retire
retire copied to clipboard
create_elasticsearch_index not wanted but can't disable...
so in model.rb, we have
def mapping(*args)
@mapping ||= {}
if block_given?
@mapping_options = args.pop
yield
create_elasticsearch_index
else
@mapping
end
end
in my model
class Product
tire do
index_name "products_current"
...
end
end
My index is an alias to an index (timestamped). This works fine in itself, but when you do something like:
rake environment tire:model:index CLASS="Product" INDEX="products-20130717"
It creates products_current, which I have to delete, then create the alias.
This is fine in most situations (though annoying) but on hosted ES which allows 1 index only, it fails to index, because its already created the one and only index you are allowed..
Can I propose we add some option to mapping like
mapping(auto_create: false) do
...
end
i totally understand your concern, but why are you using a timestamped index and an alias when your hosted ES supports only 1 index?
I wanted to test out Heroku addon SearchBox ElasticSearch βeta, which only supports single index currently (as its beta, I'm assuming)..
Besides the point though :)
what do you think of putting this in a configuration like
Tire.configure do
auto_create false
end
would have the benefit of having it in place with other environment specific configuration like urls etc.
That sounds reasonable, my only concern is when more than one index is in play and you want different functionality for each.. This is why I suggested it in the model level.
On Wed, Jul 17, 2013 at 2:33 PM, Peter Schröder [email protected]:
what do you think of putting this in a configuration like
Tire.configure do auto_create falseend
would have the benefit of having it in place with other environment specific configuration like urls etc.
— Reply to this email directly or view it on GitHubhttps://github.com/karmi/tire/issues/798#issuecomment-21112772 .
Michael
www.brightbits.co.uk
Company number: 08133555 Registered in England Registered office: 22 Finwell Road, Rainham, Kent, ME8 7PY
@brightbits I like the suggestion, there's an issue or two already opened for this. This would be easy to handle -- just delete
the setting from mapping and conditionally perform create_elasticsearch_index
. I'm on a vacation this week, will try to look into it next week.
This used to bother me on principle because it's a surprising side effect of code that is essentially declarative configuration, but now I've actually been bitten by it in a real-world way:
I have Tire::Model::Persistence
models with an object hierarchy something like this:
module Services
module Twitter
class Status
include Tire::Model::Persistence
end
class Mention
include Tire::Model::Persistence
end
end
module Facebook
class Like
include Tire::Model::Persistence
end
end
# etc
end
These are set up with a naming convention that each class is a type and its containing module is an index. I do not want create_elasticsearch_index
running automatically, because only the first type that loads in one of these modules will get its mapping correctly configured by that automatic call, the rest silently fail and I'll have to go behind it and do PUT mappings manually before any data hits it (or rather, write a Rake task to do all this properly, in which case the automatic calls are nothing but a nuisance).
I think this should not only be an option (easily implemented here as @karmi says), but it should be off by default in a future major version.
@karmi i too would like to turn off automatic index creation, as I am using aliases and if the index is automatically created I then have to delete it in order to create the alias. Any progress?
@sgringwe I think the right way would be to create the index+alias(es) in advance, then the automatic behaviour doesn't kick in. I'm afraid the behaviour in the gem won't be changed -- there will be no breaking changes in behaviour or adding of functionality. See https://github.com/elasticsearch/elasticsearch-ruby and https://github.com/elasticsearch/elasticsearch-rails