Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MODEL] Automatic index configuration using .yml or .json files #351

Closed
wants to merge 6 commits into from

Conversation

dabit
Copy link

@dabit dabit commented Mar 21, 2015

With this patch, the elasticsearch-model gem will search for .yml or .json files named after the document_type of every class and load it into @settings and @mappings accordingly.

From README:

Configuration files

Elasticseach-model will automatically load settings and mappings included in
a .yml or .json file named after the document_type that exists in
config/elasticsearch for any specific class.

# In: config/elasticsearch/article.yml
#
settings:
  number_of_shards: 7
  analyzer:
    my-analyzer:
      tokenizer: "whitespace"
mappings:
  article:
    properties:
      name:
        analyzer: "my-analyzer"
Article.settings
# => {"number_of_shards"=>7, "analyzer"=>{"my-analyzer"=>{"tokenizer"=>"whitespace"}}}

Article.mappings
# => {"article"=>{"properties"=>{"name"=>{"analyzer"=>"my-analyzer"}}}}

@dabit dabit changed the title Automatic index configuration using .yml or .json files [MODEL] Automatic index configuration using .yml or .json files Mar 21, 2015
@chrisdebruin
Copy link

+1

@dabit
Copy link
Author

dabit commented Apr 7, 2015

Hey @karmi,

Hope you had a great vacation, just a friendly reminder of these changes.

@karmi
Copy link
Contributor

karmi commented Apr 8, 2015

@dabit Sorry for the long delay! I got stalled with stuff after the return.

I'm not entirely sold on the "convention over configuration" approach in this case, I must say... I like the original approach much more... This also makes it dependent on Rails' config folder. What do you think about returning to the original approach?

@dabit
Copy link
Author

dabit commented Apr 9, 2015

@karmi ok, I really am inclined to the Rails way but I also see your point. Allow me to make the changes on the other approach (#346) and then you decide what to merge.

Thanks!

@karmi
Copy link
Contributor

karmi commented Apr 22, 2015

Hi @dabit, I still like the initial approach in #346 more, sorry :) I'm just pinging here that I think it's a great feature -- there's no time pressure, though, so please ping me when you have something new!

@dabit
Copy link
Author

dabit commented Apr 22, 2015

@karmi Hey! Haven't forgotten, just that things got a little crazy at work for the last couple of weeks. I'm pretty sure I'll have time to improve #346 within the next week or so. Sorry about the radio silence.

karmi pushed a commit that referenced this pull request May 21, 2015
… or JSON file

This change allows you to specify a YAML file with settings for the indices.

It would be helpful if you want to reuse analyzers in many different indexes.

Also, YAML is much more readable than hashes in ruby code.

Example:

    # config/elasticsearch/custom_analyzers.yml
    #
    # number_of_shards: 5
    # analysis:
    #   analyzer:
    #     my_custom_analyzer:
    #       tokenizer: "whitespace"
    #       filter: ["lowercase", "asciifolding"]
    #

    class Article
      include Elasticsearch::Model

      settings "config/elasticsearch/custom_analyzers.yml"
    end

    class Author
      include Elasticsearch::Model

      settings "config/elasticsearch/custom_analyzers.yml"
    end

Closes: #346
Closes: #351
karmi pushed a commit that referenced this pull request May 21, 2015
karmi pushed a commit that referenced this pull request May 21, 2015
@karmi
Copy link
Contributor

karmi commented May 21, 2015

Closed via 5c7cd12

@karmi karmi closed this May 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants