elastic_ar_sync 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35a997c8ae813e7a3e34ab3d5dc557e5282322078416597e85608aa34b33c18a
4
- data.tar.gz: 3f0785cd76f8ca81283119fc6ddc04262f52275645db6986aab779fd1b4c2259
3
+ metadata.gz: e5064e37715c757321f546ba33bba3804a074ea847abacbd62e2b8c8b97bf650
4
+ data.tar.gz: 2cc2dd0be8de3705775eed297c0e9b4a1464a73f7ae93f68801b6155bd439746
5
5
  SHA512:
6
- metadata.gz: f1ec8db00e1d659cf7884db47befbf49cd4a3b087b37c74ad1352c5510dd2b6667a469a36bad3d620549325c38307dcbcd08c725ae7e42a05ca349183db42bff
7
- data.tar.gz: 14d0ec670343d14d8d399ad3dcb00bca90987593a545f1d5dad888d1543ebfc180d618e1da95793aaf930c2910f42d2d6b34e50ec0bd8543147ef5371f2b3c07
6
+ metadata.gz: 2f1d68abc5470a9e7fe8dcea07b20532ace4d9307d20fac684191daff36bfe16e6cd8e77ea3d82680f158c1e685fcb4b25f596d397e0f308ed7c9e75dbf3d100
7
+ data.tar.gz: 505adfb0db637e619873cb31c54c07d75fa5a7f5056492cf3fc34509dff7592a1d6ee86a111aa48a8ef732a142d5299a7728819b75aa0be81085df8145cc2cbf
@@ -67,24 +67,32 @@ module ElasticArSync
67
67
  ElasticArSync::Elastic::Services::IndexHandler.new(self).switch_alias(alias_name: index_name, new_index_name: new_index_name)
68
68
  end
69
69
 
70
- def index_config(dynamic: 'false', number_of_shards: 1, attr_mappings: default_index_mapping)
71
- settings index: { number_of_shards: number_of_shards } do
70
+ def index_config(dynamic: 'false', override_settings: {}, attr_mappings: default_index_mapping, override_mappings: {})
71
+ attr_mappings.merge!(override_mappings) if override_mappings.present?
72
+
73
+ settings default_index_setting.merge!(override_settings) do
72
74
  # ES6からStringが使えないのでtextかkeywordにする。
73
75
  mappings dynamic: dynamic do
74
76
  attr_mappings.each do |key, value|
75
- indexes key, type: value
77
+ next unless value.is_a?(Hash)
78
+
79
+ indexes key, value
76
80
  end
77
81
  end
78
82
  end
79
83
  end
80
84
 
85
+ def default_index_setting
86
+ { index: { number_of_shards: 1 } }
87
+ end
88
+
81
89
  def default_index_mapping
82
90
  mapping = {}
83
91
  attribute_types.each do |attribute, active_model_type|
84
92
  type = active_model_type.type
85
93
  type = :text if (active_model_type.type.to_sym == :string) || (type == :integer && defined_enums.symbolize_keys.keys.include?(attribute.to_sym))
86
94
  type = :date if active_model_type.type == :datetime
87
- mapping[attribute.to_sym] = type
95
+ mapping[attribute.to_sym] = { type: type }
88
96
  end
89
97
  mapping
90
98
  end
@@ -100,6 +108,14 @@ module ElasticArSync
100
108
  raise Elasticsearch::Transport::Transport::Errors::NotFound, "インデックスがありません alias_name: #{alias_name}"
101
109
  end
102
110
  end
111
+
112
+ def current_index
113
+ get_aliases.select { |_, value| value["aliases"].present? }.keys.first
114
+ end
115
+
116
+ def current_mapping
117
+ __elasticsearch__.client.indices.get_mapping[current_index]["mappings"]["_doc"]["properties"]
118
+ end
103
119
  end
104
120
  end
105
121
  end
@@ -1,3 +1,3 @@
1
1
  module ElasticArSync
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_ar_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - KitakatsuTed