es-elasticity 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/README.md +10 -6
- data/Rakefile +2 -0
- data/elasticity.gemspec +2 -1
- data/lib/elasticity/document.rb +2 -2
- data/lib/elasticity/index.rb +1 -1
- data/lib/elasticity/multi_search.rb +5 -3
- data/lib/elasticity/railtie.rb +19 -0
- data/lib/elasticity/search.rb +3 -3
- data/lib/elasticity/version.rb +1 -1
- data/lib/elasticity_base.rb +10 -14
- data/spec/rspec_config.rb +4 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b092a148409adc4a7e11885a4be8a235d7933dcb
|
4
|
+
data.tar.gz: 8049626e93cbeb9f26d5f88859fa422b6425925c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa7dd7e2e17f990df9a65fc62ca31b7c498374e35ff95051f77747a3d41ec859eb65ecef3bf33ebd9149eadf7781f4b6d1d94cd0e7b632314f0150e8007295d6
|
7
|
+
data.tar.gz: ec226e57b6332ee5734a91272e3939218d7d80dc71c4eebe60d86a275eebbea0563e52ced4f5452f4bad57ef4b079ffe6fcb5b9302e354ffa7e445807386c5e9
|
data/.travis.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.1
|
4
|
+
- 2.0.0
|
5
|
+
services:
|
6
|
+
- elasticsearch
|
7
|
+
env:
|
8
|
+
global:
|
9
|
+
- secure: "HZa3D2GGwC6Jl062LJulbWZLTCieeBFC3FOJrArC5ul7ACGR5CEtANe0/UTnIf/Ad40p7I5VhiTdNFTcHunTbNc7Ae7dE5fOkiBHtxo/zwgpvHZK0iPvIoxsSfdcHobHeaF7NvfcXUkYUKcdRUyplHdB56eHQqYPVsah66K/4XA="
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Elasticity
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/doximity/es-elasticity.svg)](https://travis-ci.org/doximity/es-elasticity) [![Test Coverage](https://codeclimate.com/github/doximity/es-elasticity/badges/coverage.svg)](https://codeclimate.com/github/doximity/es-elasticity) [![Code Climate](https://codeclimate.com/github/doximity/es-elasticity/badges/gpa.svg)](https://codeclimate.com/github/doximity/es-elasticity) [![Dependency Status](https://gemnasium.com/doximity/es-elasticity.svg)](https://gemnasium.com/doximity/es-elasticity)
|
4
|
+
|
3
5
|
Elasticity provides a higher level abstraction on top of [elasticsearch-ruby](https://github.com/elasticsearch/elasticsearch-ruby) gem.
|
4
6
|
|
5
|
-
Mainly, it provides a model-oriented approach to
|
7
|
+
Mainly, it provides a model-oriented approach to Elasticsearch, similar to what [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord) provides to relational databases. It leverages [ActiveModel](https://github.com/rails/rails/tree/master/activemodel) to provide a familiar format for Rails developers.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -97,25 +99,27 @@ adults.active_recors(Database::User) # => Array of Database::User instances
|
|
97
99
|
|
98
100
|
## Design Goals
|
99
101
|
|
100
|
-
- Provide model specific for
|
102
|
+
- Provide model specific for Elasticsearch documents instead of an ActiveRecord mixin;
|
101
103
|
- proper separation of concerns and de-coupling;
|
102
104
|
- lazy search evaluation and easy composition of multi-searches;
|
103
105
|
- easy of debug;
|
104
|
-
- higher level API that resembles
|
106
|
+
- higher level API that resembles Elasticsearch API;
|
105
107
|
|
106
108
|
## Roadmap
|
107
109
|
|
110
|
+
- [ ] Index aliasing support
|
111
|
+
- [ ] Index hot swapping support
|
108
112
|
- [ ] Use mapping instead of mappings, we wanna be consistent to ES not to elasticsearch-ruby
|
109
|
-
- [ ]
|
110
|
-
- [ ] Support for multiple document types
|
113
|
+
- [ ] Define from_active_record interface
|
111
114
|
- [ ] Write more detailed documentation section for:
|
112
115
|
- [ ] Model definition
|
113
116
|
- [ ] Indexing, Bulk Indexing and Delete By Query
|
114
117
|
- [ ] Search and Multi Search
|
115
118
|
- [ ] ActiveRecord integration
|
119
|
+
- [ ] Better automatic index name and document type
|
120
|
+
- [ ] Support for multiple document types
|
116
121
|
- [ ] Get rid of to_document, generate automatically based on attributes
|
117
122
|
- [ ] Add some delegations on Document to Index
|
118
|
-
- [ ] Define from_active_record interface
|
119
123
|
|
120
124
|
## Contributing
|
121
125
|
|
data/Rakefile
CHANGED
data/elasticity.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Elasticity::VERSION
|
9
9
|
spec.authors = ["Rodrigo Kochenburger"]
|
10
10
|
spec.email = ["rodrigo@doximity.com"]
|
11
|
-
spec.summary = %q{ActiveModel-based library for working with
|
11
|
+
spec.summary = %q{ActiveModel-based library for working with Elasticsearch}
|
12
12
|
spec.description = %q{Elasticity provides a higher level abstraction on top of [elasticsearch-ruby](https://github.com/elasticsearch/elasticsearch-ruby) gem}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "simplecov", "~> 0.7.1"
|
26
26
|
spec.add_development_dependency "oj"
|
27
27
|
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
28
29
|
|
29
30
|
spec.add_dependency "activesupport", "~> 4.0"
|
30
31
|
spec.add_dependency "activemodel", "~> 4.0"
|
data/lib/elasticity/document.rb
CHANGED
@@ -59,7 +59,7 @@ module Elasticity
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# Searches the index using the parameters provided in the body hash, following the same
|
62
|
-
# structure
|
62
|
+
# structure Elasticsearch expects.
|
63
63
|
# Returns a DocumentSearch object.
|
64
64
|
def self.search(body)
|
65
65
|
DocumentSearchProxy.new(Search.new(index, document_type, body), self)
|
@@ -117,7 +117,7 @@ module Elasticity
|
|
117
117
|
|
118
118
|
# IMPLEMENT
|
119
119
|
# Returns a hash with the attributes as they should be stored in the index.
|
120
|
-
# This will be stored as _source attributes on
|
120
|
+
# This will be stored as _source attributes on Elasticsearch.
|
121
121
|
def to_document
|
122
122
|
raise NotImplementedError, "to_document needs to be implemented for #{self.class}"
|
123
123
|
end
|
data/lib/elasticity/index.rb
CHANGED
@@ -32,10 +32,12 @@ module Elasticity
|
|
32
32
|
{ index: search.index.name, type: search.document_type, search: search.body }
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
response = ActiveSupport::Notifications.instrument("multi_search.elasticity", args: { body: multi_body }) do
|
36
|
+
Elasticity.config.client.msearch(body: multi_body)
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
responses.each_with_index do |resp, idx|
|
39
|
+
results = {}
|
40
|
+
Array(response["responses"]).each_with_index do |resp, idx|
|
39
41
|
name, search, mapper = @searches[idx]
|
40
42
|
results[name] = Search::Result.new(resp, mapper)
|
41
43
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Elasticity
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer 'elasticity.initialize_logging' do
|
4
|
+
ActiveSupport::Notifications.subscribe(/\.elasticity$/) do |name, start, finish, id, payload|
|
5
|
+
puts name
|
6
|
+
time = (finish - start)*1000
|
7
|
+
|
8
|
+
if logger = Elasticity.config.logger
|
9
|
+
logger.debug "#{name} #{"%.2f" % time}ms #{MultiJson.dump(payload[:args], pretty: Elasticity.config.pretty_json)}"
|
10
|
+
|
11
|
+
exception, message = payload[:exception]
|
12
|
+
if exception
|
13
|
+
logger.error "#{name} #{exception}: #{message}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/elasticity/search.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Elasticity
|
2
|
-
# Search provides a simple interface for defining a search against an
|
2
|
+
# Search provides a simple interface for defining a search against an Elasticsearch
|
3
3
|
# index and fetching the results in different ways and mappings.
|
4
4
|
#
|
5
5
|
# Example:
|
@@ -12,7 +12,7 @@ module Elasticity
|
|
12
12
|
# search is not performend until methods are called, each method represents a different
|
13
13
|
# way of fetching and mapping the data.
|
14
14
|
#
|
15
|
-
# The body parameter is a hash following the exact same syntax as
|
15
|
+
# The body parameter is a hash following the exact same syntax as Elasticsearch's JSON
|
16
16
|
# query language.
|
17
17
|
def initialize(index, document_type, body)
|
18
18
|
@index = index
|
@@ -20,7 +20,7 @@ module Elasticity
|
|
20
20
|
@body = body.freeze
|
21
21
|
end
|
22
22
|
|
23
|
-
# Execute the search, fetching only ids from
|
23
|
+
# Execute the search, fetching only ids from Elasticsearch and then mapping the results
|
24
24
|
# into ActiveRecord models using the provided relation.
|
25
25
|
def active_records(relation)
|
26
26
|
return @active_record if defined?(@active_record)
|
data/lib/elasticity/version.rb
CHANGED
data/lib/elasticity_base.rb
CHANGED
@@ -7,13 +7,22 @@ require "active_support/core_ext"
|
|
7
7
|
require "active_model"
|
8
8
|
require "elasticsearch"
|
9
9
|
|
10
|
+
if defined?(Rails)
|
11
|
+
require "elasticity/railtie"
|
12
|
+
end
|
13
|
+
|
10
14
|
module Elasticity
|
11
15
|
class Config
|
12
16
|
attr_writer :logger, :client, :settings, :namespace, :pretty_json
|
13
17
|
|
14
18
|
def logger
|
15
19
|
return @logger if defined?(@logger)
|
16
|
-
|
20
|
+
|
21
|
+
if defined?(Rails)
|
22
|
+
@logger = Rails.logger
|
23
|
+
else
|
24
|
+
@logger = Logger.new(STDOUT)
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
28
|
def client
|
@@ -45,16 +54,3 @@ module Elasticity
|
|
45
54
|
@config = Config.new
|
46
55
|
end
|
47
56
|
end
|
48
|
-
|
49
|
-
ActiveSupport::Notifications.subscribe(/^elasticity\./) do |name, start, finish, id, payload|
|
50
|
-
time = (finish - start)*1000
|
51
|
-
|
52
|
-
if logger = Elasticity.config.logger
|
53
|
-
logger.debug "#{name} #{"%.2f" % time}ms #{MultiJson.dump(payload[:args], pretty: Elasticity.config.pretty_json)}"
|
54
|
-
|
55
|
-
exception, message = payload[:exception]
|
56
|
-
if exception
|
57
|
-
logger.error "#{name} #{exception}: #{message}"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/spec/rspec_config.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es-elasticity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Kochenburger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: activesupport
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,6 +161,7 @@ files:
|
|
147
161
|
- ".gitignore"
|
148
162
|
- ".rspec"
|
149
163
|
- ".simplecov"
|
164
|
+
- ".travis.yml"
|
150
165
|
- Gemfile
|
151
166
|
- LICENSE.txt
|
152
167
|
- README.md
|
@@ -158,6 +173,7 @@ files:
|
|
158
173
|
- lib/elasticity/document.rb
|
159
174
|
- lib/elasticity/index.rb
|
160
175
|
- lib/elasticity/multi_search.rb
|
176
|
+
- lib/elasticity/railtie.rb
|
161
177
|
- lib/elasticity/search.rb
|
162
178
|
- lib/elasticity/version.rb
|
163
179
|
- lib/elasticity_base.rb
|
@@ -189,7 +205,7 @@ rubyforge_project:
|
|
189
205
|
rubygems_version: 2.2.2
|
190
206
|
signing_key:
|
191
207
|
specification_version: 4
|
192
|
-
summary: ActiveModel-based library for working with
|
208
|
+
summary: ActiveModel-based library for working with Elasticsearch
|
193
209
|
test_files:
|
194
210
|
- spec/rspec_config.rb
|
195
211
|
- spec/units/document_spec.rb
|