Elasticsearch-rails: [PERSISTENCE] Can we disable time fields?

Created on 10 Mar 2016  路  6Comments  路  Source: elastic/elasticsearch-rails

We're using the persistence gem to make interacting with our documents a little easier. One thing I've noticed that Elasticsearch::Persistence::Model is kind enough to add the time fields created_at and updated_at. I'm wondering if we can disable that in some way?

For example, our code has the following structure (note: ::Sentiment is used inside ::Keyword):

module OurModule
  class Keyword
    include Elasticsearch::Persistence::Model

    attribute :relevance, Float
    attribute :sentiment, OurModule::Sentiment
    attribute :text, String
  end
end

module OurModule
  class Sentiment
    include Elasticsearch::Persistence::Model

    attribute :score, Float
    attribute :type, String
  end
end

Which, when persisted, results in the follow document:

            "_source": {
               "created_at": "2016-03-10T17:03:02.046Z",
               "updated_at": "2016-03-10T17:03:02.050Z",
               "keywords": [
                  {
                     "created_at": "2016-03-10T17:03:02.045Z",
                     "updated_at": "2016-03-10T17:03:02.045Z",
                     "relevance": 0.923899,
                     "sentiment": {
                        "created_at": "2016-03-10T17:03:02.045Z",
                        "updated_at": "2016-03-10T17:03:02.045Z",
                        "score": -0.45775,
                        "type": "negative"
                     },
                     "text": "hour-long Cowboy Christmas"
                  },
...

I'd rather not have created_at and updated_at duplicated in the document at the sentiment and keyword level. Is it possible to disable them at the model level?

Thanks!

stale

Most helpful comment

I support the idea of having a way to turn off timestamp attributes. That will give developers better choice to use the gem in a more effective and meaningful way. Please consider moving this issue forward.

Thanks!

All 6 comments

At this time, it's baked into the library, but there's no reason it shouldn't be optional... I just don't see a nice way how to achieve it, without a dumb "settings" method like add_timestamps false or whatever...?

Ill take a stab at coming up with a solution. However, when you say 'dumb "settings"', are you expressing your opposition to 'add_timestamps false' or you are describing that option as a reasonable 'simple' approach?

Yeah, I'm afraid I'm against something like add_timestamps false :), because I feel like it's a road to hell... Can we do something else, like move it to a module, and not include that module automatically? Of course, breaking backwards compatibility, but that's acceptable I think. Maybe there's another clever solution...

I support the idea of having a way to turn off timestamp attributes. That will give developers better choice to use the gem in a more effective and meaningful way. Please consider moving this issue forward.

Thanks!

Can confirm @AaronRustad! Some times it is not required to have timestamps. Any idea how to remove it?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings