elastic-rails 0.5.0 → 0.6.0
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 +4 -4
- data/lib/elastic/commands/build_agg_from_params.rb +37 -20
- data/lib/elastic/commands/build_query_from_params.rb +109 -79
- data/lib/elastic/commands/build_sort_from_params.rb +41 -0
- data/lib/elastic/commands/import_index_documents.rb +1 -1
- data/lib/elastic/configuration.rb +14 -11
- data/lib/elastic/core/adaptor.rb +0 -1
- data/lib/elastic/core/base_middleware.rb +2 -2
- data/lib/elastic/core/default_middleware.rb +1 -1
- data/lib/elastic/core/definition.rb +53 -34
- data/lib/elastic/core/query_assembler.rb +51 -19
- data/lib/elastic/core/query_config.rb +4 -5
- data/lib/elastic/core/source_formatter.rb +12 -31
- data/lib/elastic/datatypes/date.rb +32 -0
- data/lib/elastic/datatypes/default.rb +74 -0
- data/lib/elastic/datatypes/string.rb +7 -0
- data/lib/elastic/datatypes/term.rb +10 -0
- data/lib/elastic/datatypes/time.rb +29 -0
- data/lib/elastic/dsl/bool_query_builder.rb +4 -0
- data/lib/elastic/fields/nested.rb +24 -6
- data/lib/elastic/fields/value.rb +69 -25
- data/lib/elastic/nested_query.rb +34 -0
- data/lib/elastic/nested_type.rb +10 -0
- data/lib/elastic/nodes/agg/average.rb +3 -1
- data/lib/elastic/nodes/agg/base_metric.rb +6 -5
- data/lib/elastic/nodes/agg/date_histogram.rb +4 -4
- data/lib/elastic/nodes/agg/maximum.rb +3 -1
- data/lib/elastic/nodes/agg/minimum.rb +3 -1
- data/lib/elastic/nodes/agg/stats.rb +3 -1
- data/lib/elastic/nodes/agg/sum.rb +3 -1
- data/lib/elastic/nodes/agg/terms.rb +4 -4
- data/lib/elastic/nodes/agg/top_hits.rb +6 -6
- data/lib/elastic/nodes/and.rb +2 -2
- data/lib/elastic/nodes/base.rb +5 -3
- data/lib/elastic/nodes/base_agg.rb +2 -2
- data/lib/elastic/nodes/boolean.rb +34 -14
- data/lib/elastic/nodes/concerns/aggregable.rb +12 -8
- data/lib/elastic/nodes/concerns/bucketed.rb +4 -7
- data/lib/elastic/nodes/concerns/field_query.rb +10 -0
- data/lib/elastic/nodes/concerns/hit_provider.rb +11 -0
- data/lib/elastic/nodes/function_score.rb +8 -7
- data/lib/elastic/nodes/match.rb +6 -5
- data/lib/elastic/nodes/nested.rb +28 -7
- data/lib/elastic/nodes/range.rb +9 -8
- data/lib/elastic/nodes/search.rb +11 -10
- data/lib/elastic/nodes/sort.rb +82 -0
- data/lib/elastic/nodes/term.rb +7 -6
- data/lib/elastic/query.rb +24 -12
- data/lib/elastic/railtie.rb +7 -0
- data/lib/elastic/railties/ar_helpers.rb +2 -1
- data/lib/elastic/railties/configuration_extensions.rb +13 -0
- data/lib/elastic/railties/indexable_record.rb +1 -2
- data/lib/elastic/railties/indexing_job.rb +8 -0
- data/lib/elastic/railties/type_extensions.rb +1 -1
- data/lib/elastic/results/aggregations.rb +1 -1
- data/lib/elastic/results/bucket.rb +3 -2
- data/lib/elastic/results/grouped_result.rb +31 -1
- data/lib/elastic/results/hit.rb +8 -20
- data/lib/elastic/results/hit_collection.rb +2 -33
- data/lib/elastic/results/root.rb +3 -2
- data/lib/elastic/results/scored_collection.rb +44 -0
- data/lib/elastic/results/scored_item.rb +10 -0
- data/lib/elastic/shims/base.rb +6 -4
- data/lib/elastic/shims/concerns/hit_picker.rb +41 -0
- data/lib/elastic/shims/field_picking.rb +20 -0
- data/lib/elastic/shims/grouping.rb +17 -8
- data/lib/elastic/shims/id_picking.rb +15 -0
- data/lib/elastic/shims/populating.rb +4 -11
- data/lib/elastic/shims/reducing.rb +3 -7
- data/lib/elastic/shims/total_picking.rb +16 -0
- data/lib/elastic/type.rb +6 -3
- data/lib/elastic/types/base_type.rb +16 -9
- data/lib/elastic/types/faceted_type.rb +1 -1
- data/lib/elastic/types/nestable_type.rb +2 -2
- data/lib/elastic/version.rb +1 -1
- data/lib/elastic.rb +15 -0
- data/lib/generators/elastic/index_generator.rb +1 -1
- data/lib/generators/elastic/init_generator.rb +10 -0
- data/lib/generators/elastic/templates/elastic.yml +14 -0
- data/lib/generators/elastic/templates/index.rb +0 -1
- metadata +21 -2
data/lib/elastic/railtie.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require "elastic/railties/utils"
|
2
2
|
require "elastic/railties/ar_helpers"
|
3
3
|
require "elastic/railties/ar_middleware"
|
4
|
+
require "elastic/railties/configuration_extensions"
|
4
5
|
require "elastic/railties/type_extensions"
|
5
6
|
require "elastic/railties/query_extensions"
|
7
|
+
require "elastic/railties/indexing_job"
|
6
8
|
require "elastic/railties/indexable_record"
|
7
9
|
|
8
10
|
module Elastic
|
@@ -27,6 +29,11 @@ module Elastic
|
|
27
29
|
extend Elastic::Railties::Utils
|
28
30
|
end
|
29
31
|
|
32
|
+
# Add activerecord related configuration parameters
|
33
|
+
module Elastic::Configuration
|
34
|
+
include Elastic::Railties::ConfigurationExtensions
|
35
|
+
end
|
36
|
+
|
30
37
|
# Add activerecord related index helpers
|
31
38
|
class Elastic::Type
|
32
39
|
include Elastic::Railties::TypeExtensions
|
@@ -42,7 +42,8 @@ module Elastic::Railties
|
|
42
42
|
when :string then { type: :string, index: 'not_analyzed' }
|
43
43
|
when :integer then { type: :long } # not sure..
|
44
44
|
when :float, :decimal then { type: :double } # not sure..
|
45
|
-
when :
|
45
|
+
when :date then { type: :date }
|
46
|
+
when :datetime then { type: :time }
|
46
47
|
when :boolean then { type: :boolean }
|
47
48
|
end
|
48
49
|
end
|
@@ -7,7 +7,7 @@ module Elastic::Railties
|
|
7
7
|
module ClassMethods
|
8
8
|
def references(*_includes)
|
9
9
|
# TODO: check target allows options
|
10
|
-
|
10
|
+
pre_definition.middleware_options[:ar_collect_includes] = _includes
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -2,7 +2,10 @@ module Elastic::Results
|
|
2
2
|
class GroupedResult < Base
|
3
3
|
include Enumerable
|
4
4
|
|
5
|
-
|
5
|
+
attr_reader :key_names
|
6
|
+
|
7
|
+
def initialize(_key_names, _groups)
|
8
|
+
@key_names = _key_names.freeze
|
6
9
|
@groups = _groups.to_a
|
7
10
|
end
|
8
11
|
|
@@ -10,6 +13,19 @@ module Elastic::Results
|
|
10
13
|
@groups.map { |g| group_as_pair g }.each(&_block)
|
11
14
|
end
|
12
15
|
|
16
|
+
def [](_key)
|
17
|
+
if _key.is_a? Hash
|
18
|
+
mapped_results[_key]
|
19
|
+
else
|
20
|
+
raise ArgumentError, '' if @key_names.length > 1
|
21
|
+
mapped_results[@key_names.first => _key]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def each_group(&_block)
|
26
|
+
@groups.each(&_block)
|
27
|
+
end
|
28
|
+
|
13
29
|
def last
|
14
30
|
return nil if @groups.count == 0
|
15
31
|
group_as_pair @groups.last
|
@@ -28,10 +44,24 @@ module Elastic::Results
|
|
28
44
|
@groups.each { |h| h.traverse(&_block) }
|
29
45
|
end
|
30
46
|
|
47
|
+
def map_to_group(&_block)
|
48
|
+
self.class.new(@key_names, @groups.map do |group|
|
49
|
+
Elastic::Results::ResultGroup.new group.keys, _block.call(group.as_value)
|
50
|
+
end)
|
51
|
+
end
|
52
|
+
|
31
53
|
private
|
32
54
|
|
33
55
|
def group_as_pair(_group)
|
34
56
|
[_group.keys, _group.as_value]
|
35
57
|
end
|
58
|
+
|
59
|
+
def mapped_results
|
60
|
+
@mapped_results ||= {}.tap do |map|
|
61
|
+
@groups.each do |g|
|
62
|
+
map[g.keys] = g.as_value
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
36
66
|
end
|
37
67
|
end
|
data/lib/elastic/results/hit.rb
CHANGED
@@ -1,25 +1,13 @@
|
|
1
1
|
module Elastic::Results
|
2
2
|
class Hit < Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@
|
11
|
-
end
|
12
|
-
|
13
|
-
def type
|
14
|
-
@raw['_type']
|
15
|
-
end
|
16
|
-
|
17
|
-
def score
|
18
|
-
@raw['_score']
|
19
|
-
end
|
20
|
-
|
21
|
-
def source
|
22
|
-
@raw['_source']
|
3
|
+
attr_reader :type, :id, :score, :source
|
4
|
+
attr_accessor :data
|
5
|
+
|
6
|
+
def initialize(_type, _id, _score, _source)
|
7
|
+
@type = _type
|
8
|
+
@id = _id
|
9
|
+
@score = _score
|
10
|
+
@source = _source
|
23
11
|
end
|
24
12
|
end
|
25
13
|
end
|
@@ -1,38 +1,7 @@
|
|
1
1
|
module Elastic::Results
|
2
|
-
class HitCollection <
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
def initialize(_hits)
|
6
|
-
@hits = _hits
|
7
|
-
end
|
8
|
-
|
9
|
-
def count
|
10
|
-
@hits.count
|
11
|
-
end
|
12
|
-
|
13
|
-
def [](_idx)
|
14
|
-
@hits[_idx].try(:ref)
|
15
|
-
end
|
16
|
-
|
17
|
-
def last
|
18
|
-
@hits.last.try(:ref)
|
19
|
-
end
|
20
|
-
|
21
|
-
def each(&_block)
|
22
|
-
@hits.map(&:ref).each(&_block)
|
23
|
-
end
|
24
|
-
|
2
|
+
class HitCollection < ScoredCollection
|
25
3
|
def each_hit(&_block)
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def each_with_score(&_block)
|
30
|
-
@hits.map { |h| [h.ref, h.score] }.each(&_block)
|
31
|
-
end
|
32
|
-
|
33
|
-
def traverse(&_block)
|
34
|
-
super
|
35
|
-
@hits.each { |h| h.traverse(&_block) }
|
4
|
+
collection.each(&_block)
|
36
5
|
end
|
37
6
|
end
|
38
7
|
end
|
data/lib/elastic/results/root.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Elastic::Results
|
2
2
|
class Root < HitCollection
|
3
|
-
attr_reader :aggregations
|
3
|
+
attr_reader :aggregations, :total
|
4
4
|
|
5
|
-
def initialize(_hits, _aggs)
|
5
|
+
def initialize(_hits, _total, _aggs)
|
6
6
|
super _hits
|
7
|
+
@total = _total
|
7
8
|
@aggregations = Aggregations.new _aggs
|
8
9
|
end
|
9
10
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Elastic::Results
|
2
|
+
class ScoredCollection < Base
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(_collection)
|
6
|
+
@collection = _collection
|
7
|
+
end
|
8
|
+
|
9
|
+
def count
|
10
|
+
@collection.count
|
11
|
+
end
|
12
|
+
|
13
|
+
def [](_idx)
|
14
|
+
@collection[_idx].try(:data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def last
|
18
|
+
@collection.last.try(:data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def each(&_block)
|
22
|
+
@collection.map(&:data).each(&_block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def each_with_score(&_block)
|
26
|
+
@collection.map { |sd| [sd.data, sd.score] }.each(&_block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def map_with_score(&_block)
|
30
|
+
ScoredCollection.new(
|
31
|
+
@collection.map { |sd| ScoredItem.new(_block.call(sd), sd.score) }.to_a
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def traverse(&_block)
|
36
|
+
super
|
37
|
+
@collection.each { |sd| sd.traverse(&_block) }
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_reader :collection
|
43
|
+
end
|
44
|
+
end
|
data/lib/elastic/shims/base.rb
CHANGED
@@ -12,12 +12,14 @@ module Elastic::Shims
|
|
12
12
|
@child.traverse(&_block)
|
13
13
|
end
|
14
14
|
|
15
|
-
def render
|
16
|
-
@child.render
|
15
|
+
def render(_options = {})
|
16
|
+
@child.render(_options)
|
17
17
|
end
|
18
18
|
|
19
|
-
def handle_result(_raw)
|
20
|
-
@child.handle_result(_raw)
|
19
|
+
def handle_result(_raw, _formatter)
|
20
|
+
@child.handle_result(_raw, _formatter)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
require "elastic/shims/concerns/hit_picker"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Elastic::Shims::Concerns
|
2
|
+
module HitPicker
|
3
|
+
def render(_options = {})
|
4
|
+
set_hits_source unless required_source_fields.nil?
|
5
|
+
super
|
6
|
+
end
|
7
|
+
|
8
|
+
def handle_result(_raw, _formatter)
|
9
|
+
result = super
|
10
|
+
|
11
|
+
case result
|
12
|
+
when Elastic::Results::Root
|
13
|
+
transform_collection(result)
|
14
|
+
when Elastic::Results::GroupedResult
|
15
|
+
result.map_to_group { |c| transform_collection(c) }
|
16
|
+
else
|
17
|
+
raise "unable to pick from result of type #{result.class}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def set_hits_source
|
24
|
+
child.pick(Elastic::Nodes::Concerns::HitProvider) do |node|
|
25
|
+
node.source = required_source_fields
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def transform_collection(_collection)
|
30
|
+
_collection.map_with_score { |h| pick_from_hit(h) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def pick_from_hit(_hit)
|
34
|
+
raise NotImplementedError, 'pick_from_hit not implemented'
|
35
|
+
end
|
36
|
+
|
37
|
+
def required_source_fields
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Elastic::Shims
|
2
|
+
class FieldPicking < Base
|
3
|
+
include Elastic::Shims::Concerns::HitPicker
|
4
|
+
|
5
|
+
def initialize(_child, _field)
|
6
|
+
super(_child)
|
7
|
+
@field = _field
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def pick_from_hit(_hit)
|
13
|
+
_hit.source[@field]
|
14
|
+
end
|
15
|
+
|
16
|
+
def required_source_fields
|
17
|
+
[@field]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,23 +1,32 @@
|
|
1
1
|
module Elastic::Shims
|
2
2
|
class Grouping < Base
|
3
|
-
def handle_result(_raw)
|
4
|
-
|
5
|
-
group_recursive(super.aggregations,
|
6
|
-
Elastic::Results::GroupedResult.new groups
|
3
|
+
def handle_result(_raw, _formatter)
|
4
|
+
chain = extract_aggregation_chain
|
5
|
+
groups = group_recursive(super.aggregations, chain)
|
6
|
+
Elastic::Results::GroupedResult.new chain, groups
|
7
7
|
end
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def extract_aggregation_chain
|
12
|
+
child.pick(Elastic::Nodes::Concerns::Aggregable).map do |node|
|
13
|
+
bucketed = node.aggregations.find { |n| n.is_a? Elastic::Nodes::Concerns::Bucketed }
|
14
|
+
bucketed.try(:name)
|
15
|
+
end.reject(&:nil?)
|
16
|
+
end
|
13
17
|
|
14
|
-
|
18
|
+
def group_recursive(_agg_context, _chain, _keys = {}, _groups = [], _idx = 0)
|
19
|
+
if _idx < _chain.length
|
20
|
+
name = _chain[_idx]
|
21
|
+
agg = _agg_context[name] || []
|
15
22
|
agg.each do |bucket|
|
16
|
-
group_recursive(bucket, _keys.merge(name => bucket.key), _groups)
|
23
|
+
group_recursive(bucket, _chain, _keys.merge(name => bucket.key), _groups, _idx + 1)
|
17
24
|
end
|
18
25
|
else
|
19
26
|
_groups << Elastic::Results::ResultGroup.new(_keys, _agg_context)
|
20
27
|
end
|
28
|
+
|
29
|
+
_groups
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
@@ -6,12 +6,12 @@ module Elastic::Shims
|
|
6
6
|
@config = _config
|
7
7
|
end
|
8
8
|
|
9
|
-
def render
|
9
|
+
def render(_options = {})
|
10
10
|
disable_hits_source if populate_by_id?
|
11
11
|
super
|
12
12
|
end
|
13
13
|
|
14
|
-
def handle_result(_raw)
|
14
|
+
def handle_result(_raw, _formatter)
|
15
15
|
result = super
|
16
16
|
populate result
|
17
17
|
result
|
@@ -37,13 +37,10 @@ module Elastic::Shims
|
|
37
37
|
if populate_by_id?
|
38
38
|
ids = _hits.map(&:id)
|
39
39
|
objects = target.find_by_ids(ids, middleware_options)
|
40
|
-
objects.each_with_index { |o, i| _hits[i].
|
40
|
+
objects.each_with_index { |o, i| _hits[i].data = o }
|
41
41
|
else
|
42
42
|
_hits.each do |hit|
|
43
|
-
hit.
|
44
|
-
formatter.format(hit.source),
|
45
|
-
middleware_options
|
46
|
-
)
|
43
|
+
hit.data = target.build_from_data(hit.source, middleware_options)
|
47
44
|
end
|
48
45
|
end
|
49
46
|
end
|
@@ -61,9 +58,5 @@ module Elastic::Shims
|
|
61
58
|
@index.definition.middleware_options.merge(@config.middleware_options).freeze
|
62
59
|
end
|
63
60
|
end
|
64
|
-
|
65
|
-
def formatter
|
66
|
-
@formatter ||= Elastic::Core::SourceFormatter.new(@index.mapping)
|
67
|
-
end
|
68
61
|
end
|
69
62
|
end
|
@@ -1,19 +1,15 @@
|
|
1
1
|
module Elastic::Shims
|
2
2
|
class Reducing < Base
|
3
|
-
def handle_result(_raw)
|
3
|
+
def handle_result(_raw, _formatter)
|
4
4
|
result = super
|
5
5
|
|
6
6
|
case result
|
7
7
|
when Elastic::Results::Root
|
8
8
|
result.aggregations.first.last.as_value
|
9
9
|
when Elastic::Results::GroupedResult
|
10
|
-
|
11
|
-
Elastic::Results::ResultGroup.new keys, bucket.first.last
|
12
|
-
end
|
13
|
-
|
14
|
-
Elastic::Results::GroupedResult.new groups
|
10
|
+
result.map_to_group { |b| b.first.last }
|
15
11
|
else
|
16
|
-
result
|
12
|
+
raise "unable to reduce result of type #{result.class}"
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Elastic::Shims
|
2
|
+
class TotalPicking < Base
|
3
|
+
def handle_result(_raw, _formatter)
|
4
|
+
result = super
|
5
|
+
|
6
|
+
case result
|
7
|
+
when Elastic::Results::Root
|
8
|
+
result.total
|
9
|
+
when Elastic::Results::GroupedResult
|
10
|
+
result.map_to_group { |bucket| Elastic::Results::Metric.new(bucket.total) }
|
11
|
+
else
|
12
|
+
raise "unable to pick from result of type #{result.class}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/elastic/type.rb
CHANGED
@@ -81,13 +81,16 @@ module Elastic
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
|
85
|
-
freeze_index_definition
|
84
|
+
def self.load_mapping
|
86
85
|
Elastic::Core::MappingManager.new(adaptor, definition).tap(&:fetch)
|
87
86
|
end
|
88
87
|
|
89
|
-
private_class_method
|
88
|
+
private_class_method :load_mapping
|
89
|
+
|
90
|
+
def self.default_suffix
|
90
91
|
to_s.underscore
|
91
92
|
end
|
93
|
+
|
94
|
+
private_class_method :default_suffix
|
92
95
|
end
|
93
96
|
end
|
@@ -1,38 +1,45 @@
|
|
1
1
|
module Elastic::Types
|
2
2
|
class BaseType < Elastic::Core::Serializer
|
3
3
|
def self.target=(_name_or_class)
|
4
|
-
|
4
|
+
pre_definition.targets = [_name_or_class]
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.targets=(_names_or_classes)
|
8
|
-
|
8
|
+
pre_definition.targets = _names_or_classes
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
12
|
-
@
|
11
|
+
def self.pre_definition
|
12
|
+
@pre_definition ||= Elastic::Core::Definition.new.tap do |definition|
|
13
13
|
definition.targets = [default_target] unless default_target.nil?
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.
|
18
|
-
|
19
|
-
|
17
|
+
def self.definition
|
18
|
+
@definition ||= begin
|
19
|
+
pre_definition.fields.each do |field|
|
20
20
|
field.disable_mapping_inference if original_value_occluded? field.name
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
pre_definition.freeze
|
24
|
+
pre_definition
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
28
|
+
def self.freeze_definition
|
29
|
+
definition # calling definition freezes it
|
30
|
+
end
|
31
|
+
|
27
32
|
def initialize(_object)
|
28
33
|
super(self.class.definition, _object)
|
29
34
|
end
|
30
35
|
|
31
|
-
|
36
|
+
def self.default_target
|
32
37
|
@default_target ||= begin
|
33
38
|
target = to_s.match(/^(.*)Index$/)
|
34
39
|
target ? target[1] : nil
|
35
40
|
end
|
36
41
|
end
|
42
|
+
|
43
|
+
private_class_method :default_target
|
37
44
|
end
|
38
45
|
end
|
@@ -6,9 +6,9 @@ module Elastic::Types
|
|
6
6
|
using.target = (target || _name.to_s.singularize.camelize.constantize) rescue nil
|
7
7
|
end
|
8
8
|
|
9
|
-
using = (_name + '_index').camelize.constantize if using.nil?
|
9
|
+
using = (_name.to_s.singularize + '_index').camelize.constantize if using.nil?
|
10
10
|
|
11
|
-
|
11
|
+
pre_definition.register_field Elastic::Fields::Nested.new(_name, using)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/elastic/version.rb
CHANGED