diff options
author | 2018-01-16 23:10:40 -0500 | |
---|---|---|
committer | 2018-01-16 23:10:40 -0500 | |
commit | c0dea2c99c7bd5b6edd0ff751822dc75a377c3cf (patch) | |
tree | f4c01c9e2f7f9ee72c408966d70c31ac15c5dc20 | |
parent | Fix typo that broke compilation. (diff) | |
download | packages-5-c0dea2c99c7bd5b6edd0ff751822dc75a377c3cf.tar.gz packages-5-c0dea2c99c7bd5b6edd0ff751822dc75a377c3cf.tar.bz2 packages-5-c0dea2c99c7bd5b6edd0ff751822dc75a377c3cf.zip |
Update ES indexing scheme for ES6.
ES6 introduces a number of breaking changes into ES.
1) https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html
This basically entails breaking up the single multi-typel index we had
into N indices, one per model. Our other option is to continue to use a
single index, but add a custom type property. This seemed unwieldy.
2) The 'String' type was also deprecated. See
https://www.elastic.co/blog/strings-are-dead-long-live-strings
So we see many updates from "not analyzed" to "keyword" to retain
the previous behavior
-rw-r--r-- | app/models/category.rb | 8 | ||||
-rw-r--r-- | app/models/change.rb | 12 | ||||
-rw-r--r-- | app/models/package.rb | 26 | ||||
-rw-r--r-- | app/models/useflag.rb | 12 | ||||
-rw-r--r-- | app/models/version.rb | 28 | ||||
-rw-r--r-- | config/initializers/elasticsearch.rb | 3 | ||||
-rw-r--r-- | lib/kkuleomi/store.rb | 41 |
7 files changed, 61 insertions, 69 deletions
diff --git a/app/models/category.rb b/app/models/category.rb index 5fa31ea..d00c88f 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -2,11 +2,11 @@ class Category include Elasticsearch::Persistence::Model include Kkuleomi::Store::Model - index_name "packages-#{Rails.env}" + index_name "categories-#{Rails.env}" - attribute :name, String, mapping: { index: 'not_analyzed' } - attribute :description, String - attribute :metadata_hash, String, mapping: { index: 'not_analyzed' } + attribute :name, String, mapping: { type: 'text' } + attribute :description, String, mapping: { type: 'text' } + attribute :metadata_hash, String, mapping: { type: 'text' } # Determines if the document model needs an update from the repository model # diff --git a/app/models/change.rb b/app/models/change.rb index 9ffe258..9ad8e70 100644 --- a/app/models/change.rb +++ b/app/models/change.rb @@ -2,12 +2,12 @@ class Change include Elasticsearch::Persistence::Model include Kkuleomi::Store::Model - index_name "packages-#{Rails.env}" + index_name "changes-#{Rails.env}" - attribute :package, String, mapping: { index: 'not_analyzed' } - attribute :category, String, mapping: { index: 'not_analyzed' } - attribute :change_type, String, mapping: { index: 'not_analyzed' } - attribute :version, String, mapping: { index: 'not_analyzed' } - attribute :arches, String, mapping: { index: 'not_analyzed' } + attribute :package, String, mapping: { type: 'text' } + attribute :category, String, mapping: { type: 'text' } + attribute :change_type, String, mapping: { type: 'text' } + attribute :version, String, mapping: { type: 'text' } + attribute :arches, String, mapping: { type: 'text' } attribute :commit, Hash, default: {}, mapping: { type: 'object' } end diff --git a/app/models/package.rb b/app/models/package.rb index 24cbd8b..1f98e04 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -6,19 +6,23 @@ class Package index_name "packages-#{Rails.env}" - attribute :category, String, mapping: { index: 'not_analyzed' } - attribute :name, String, mapping: { index: 'not_analyzed' } - attribute :name_sort, String, mapping: { index: 'not_analyzed' } - attribute :atom, String, mapping: { index: 'not_analyzed' } - attribute :description, String - attribute :longdescription, String - attribute :homepage, String, default: [], mapping: { index: 'not_analyzed' } - attribute :license, String, mapping: { index: 'not_analyzed' } - attribute :licenses, String, default: [], mapping: { index: 'not_analyzed' } - attribute :herds, String, default: [], mapping: { index: 'not_analyzed' } + raw_fields = { + type: 'keyword' + } + + attribute :category, String, mapping: raw_fields + attribute :name, String, mapping: raw_fields + attribute :name_sort, String, mapping: raw_fields + attribute :atom, String, mapping: raw_fields + attribute :description, String, mapping: raw_fields + attribute :longdescription, String, mapping: raw_fields + attribute :homepage, String, default: [], mapping: raw_fields + attribute :license, String, mapping: raw_fields + attribute :licenses, String, default: [], mapping: raw_fields + attribute :herds, String, default: [], mapping: raw_fields attribute :maintainers, Array, default: [], mapping: { type: 'object' } attribute :useflags, Hash, default: {}, mapping: { type: 'object' } - attribute :metadata_hash, String, mapping: { index: 'not_analyzed' } + attribute :metadata_hash, String, mapping: raw_fields def category_model @category_model ||= Category.find_by(:name, category) diff --git a/app/models/useflag.rb b/app/models/useflag.rb index 1139c97..65a7ecd 100644 --- a/app/models/useflag.rb +++ b/app/models/useflag.rb @@ -2,13 +2,13 @@ class Useflag include Elasticsearch::Persistence::Model include Kkuleomi::Store::Model - index_name "packages-#{Rails.env}" + index_name "useflags-#{Rails.env}" - attribute :name, String, mapping: { index: 'not_analyzed' } - attribute :description, String - attribute :atom, String, mapping: { index: 'not_analyzed' } - attribute :scope, String, mapping: { index: 'not_analyzed' } - attribute :use_expand_prefix, String, mapping: { index: 'not_analyzed' } + attribute :name, String, mapping: { type: 'text' } + attribute :description, String, mapping: { type: 'text' } + attribute :atom, String, mapping: { type: 'text' } + attribute :scope, String, mapping: { type: 'text' } + attribute :use_expand_prefix, String, mapping: { type: 'text' } def all_fields [:name, :description, :atom, :scope, :use_expand_prefix] diff --git a/app/models/version.rb b/app/models/version.rb index 1dc28f8..50d3940 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -3,21 +3,21 @@ class Version include Kkuleomi::Store::Model include Kkuleomi::Store::Models::VersionImport - index_name "packages-#{Rails.env}" - - attribute :version, String, mapping: { index: 'not_analyzed' } - attribute :package, String, mapping: { index: 'not_analyzed' } - attribute :atom, String, mapping: { index: 'not_analyzed' } - attribute :sort_key, Integer, mapping: { index: 'not_analyzed' } - attribute :slot, String, mapping: { index: 'not_analyzed' } - attribute :subslot, String, mapping: { index: 'not_analyzed' } - attribute :eapi, String, mapping: { index: 'not_analyzed' } - attribute :keywords, String, mapping: { index: 'not_analyzed' } + index_name "versions-#{Rails.env}" + + attribute :version, String, mapping: { type: 'text' } + attribute :package, String, mapping: { type: 'text' } + attribute :atom, String, mapping: { type: 'text' } + attribute :sort_key, Integer, mapping: { type: 'text' } + attribute :slot, String, mapping: { type: 'text' } + attribute :subslot, String, mapping: { type: 'text' } + attribute :eapi, String, mapping: { type: 'text' } + attribute :keywords, String, mapping: { type: 'text' } attribute :masks, Array, default: [], mapping: { type: 'object' } - attribute :use, String, default: [], mapping: { index: 'not_analyzed' } - attribute :restrict, String, default: [], mapping: { index: 'not_analyzed' } - attribute :properties, String, default: [], mapping: { index: 'not_analyzed' } - attribute :metadata_hash, String, mapping: { index: 'not_analyzed' } + attribute :use, String, default: [], mapping: { type: 'text' } + attribute :restrict, String, default: [], mapping: { type: 'text' } + attribute :properties, String, default: [], mapping: { type: 'text' } + attribute :metadata_hash, String, mapping: { type: 'text' } # Returns the keywording state on a given architecture # diff --git a/config/initializers/elasticsearch.rb b/config/initializers/elasticsearch.rb index 71a032a..dded1e4 100644 --- a/config/initializers/elasticsearch.rb +++ b/config/initializers/elasticsearch.rb @@ -1,10 +1,9 @@ require 'elasticsearch/persistence/model' Elasticsearch::Persistence.client = Elasticsearch::Client.new host: ENV['ELASTICSEARCH_URL'] || 'elasticsearch:9300' - if Rails.env.development? logger = ActiveSupport::Logger.new(STDERR) - logger.level = Logger::INFO + logger.level = Logger::DEBUG logger.formatter = proc { |s, d, p, m| "\e[2m#{m}\n\e[0m" } Elasticsearch::Persistence.client.transport.logger = logger end diff --git a/lib/kkuleomi/store.rb b/lib/kkuleomi/store.rb index 4baf2c4..61591c8 100644 --- a/lib/kkuleomi/store.rb +++ b/lib/kkuleomi/store.rb @@ -4,26 +4,15 @@ module Kkuleomi::Store end def self.create_index(force = false) - client = Category.gateway.client - index_name = Category.index_name + types = [ + Category + Package + Version + Change + Useflag + ] - settings_list = [ - Category.settings.to_hash, - Package.settings.to_hash, - Version.settings.to_hash, - Change.settings.to_hash, - Useflag.settings.to_hash - ] - - mappings_list = [ - Category.mappings.to_hash, - Package.mappings.to_hash, - Version.mappings.to_hash, - Change.mappings.to_hash, - Useflag.mappings.to_hash - ] - - settings = { + base_settings = { analysis: { filter: { autocomplete_filter: { @@ -41,13 +30,13 @@ module Kkuleomi::Store } } } - settings_list.each { |setting| settings.merge! setting } - - mappings = {} - mappings_list.each { |mapping| mappings.merge! mapping } - - client.indices.delete(index: index_name) rescue nil if force - client.indices.create(index: index_name, body: { settings: settings, mappings: mappings }) + # In ES 1.5, we could use 1 mega-index. But in ES6, each model needs its own. + types.each { |type| + client = type.Gateway.client + client.indices.delete(type.index_name) rescue nil if force + body = { settings: type.settings.to_hash, mappings: type.mappings.to_hash } + client.indices.create(index: type.index_name, body: body) + } end end |