retire icon indicating copy to clipboard operation
retire copied to clipboard

create_elasticsearch_index not wanted but can't disable...

Open mikebaldry opened this issue 11 years ago • 8 comments

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

mikebaldry avatar Jul 17 '13 10:07 mikebaldry

i totally understand your concern, but why are you using a timestamped index and an alias when your hosted ES supports only 1 index?

phoet avatar Jul 17 '13 13:07 phoet

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 :)

mikebaldry avatar Jul 17 '13 13:07 mikebaldry

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.

phoet avatar Jul 17 '13 13:07 phoet

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

mikebaldry avatar Jul 17 '13 13:07 mikebaldry

@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.

karmi avatar Jul 18 '13 08:07 karmi

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.

ches avatar Sep 06 '13 09:09 ches

@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 avatar Jul 17 '14 03:07 sgringwe

@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

karmi avatar Jul 17 '14 06:07 karmi