elastico 0.0.4 → 0.0.5
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.
- data/Gemfile.lock +1 -1
- data/README.md +25 -17
- data/lib/elastico/callbacks.rb +2 -1
- data/lib/elastico/client.rb +0 -2
- data/lib/elastico/import.rb +11 -0
- data/lib/elastico/index.rb +6 -1
- data/lib/elastico/version.rb +1 -1
- data/lib/elastico.rb +2 -1
- metadata +2 -1
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Elastico is a __simple__ layer that enables you to use elasticsearch __full__ API. The elasticsearch team created this [great API](http://www.elasticsearch.org/guide/) which enables you to do almost anything todays search engines allow you to do.
|
|
4
4
|
|
|
5
|
-
__Simple__. Elastico is built in a way so your configuration and usage is as simple and
|
|
5
|
+
__Simple__. Elastico is built in a way so your configuration and usage is as simple and straightforward as possible.
|
|
6
6
|
|
|
7
7
|
__Full__. Elastico is built to be transparent, non-blocking, non-opinionated layer between your code to elasticsearch API. Meaning Elastico won't force anything about how to index your active records models, neither how to search it.
|
|
8
8
|
|
|
@@ -21,6 +21,14 @@ In general, in order to be able to use elasticsearch search capabilities you sho
|
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
23
23
|
|
|
24
|
+
Install elasticsearch:
|
|
25
|
+
|
|
26
|
+
cd ~
|
|
27
|
+
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.5.tar.gz .
|
|
28
|
+
tar -zxvf elasticsearch-0.90.5.tar.gz /bin/
|
|
29
|
+
rm elasticsearch-0.90.5.tar.gz
|
|
30
|
+
/bin/elasticsearch-0.90.5/bin/elasticsearch -f
|
|
31
|
+
|
|
24
32
|
Add this line to your application's Gemfile:
|
|
25
33
|
|
|
26
34
|
gem 'elastico'
|
|
@@ -37,21 +45,19 @@ Or install it yourself as:
|
|
|
37
45
|
|
|
38
46
|
In your model:
|
|
39
47
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
class Apple < ActiveRecord::Base
|
|
49
|
+
include Elastico
|
|
50
|
+
attr_accessible :color, :name
|
|
51
|
+
|
|
52
|
+
def self.prepare_elastico_settings_and_mappings_json
|
|
53
|
+
json = { "apple" => {
|
|
54
|
+
"properties" => {
|
|
55
|
+
"name" => {"type" => "string"},
|
|
56
|
+
"color" => {"type" => "string"}
|
|
57
|
+
}
|
|
58
|
+
}}.to_json
|
|
59
|
+
end
|
|
49
60
|
end
|
|
50
|
-
include Elastico
|
|
51
|
-
|
|
52
|
-
attr_accessible :color, :name
|
|
53
|
-
|
|
54
|
-
end
|
|
55
61
|
|
|
56
62
|
|
|
57
63
|
In your controller:
|
|
@@ -80,7 +86,7 @@ In your controller:
|
|
|
80
86
|
|
|
81
87
|
Learn by Example
|
|
82
88
|
================
|
|
83
|
-
Fork the example app that shows how to use Elastico [here](https://github.com/gneyal/ElasticoExample).
|
|
89
|
+
Fork/Clone the example app that shows how to use Elastico [here](https://github.com/gneyal/ElasticoExample).
|
|
84
90
|
|
|
85
91
|
|
|
86
92
|
Configure it
|
|
@@ -102,9 +108,11 @@ __Optional__
|
|
|
102
108
|
|
|
103
109
|
3. Set up Apple.elastico\_type\_name (optional - defaults to your class name; here it will be Apple).
|
|
104
110
|
|
|
111
|
+
4. Run Apple.elastico_import_all to import all your data.
|
|
112
|
+
|
|
105
113
|
Use it.
|
|
106
114
|
-------
|
|
107
|
-
1. After every save Elastico will automatically save
|
|
115
|
+
1. After every save Elastico will automatically save your instance in elasticsearch.
|
|
108
116
|
|
|
109
117
|
2. Import current database instances by creating a rake task to "save" them all.
|
|
110
118
|
|
data/lib/elastico/callbacks.rb
CHANGED
|
@@ -3,7 +3,8 @@ module Elastico
|
|
|
3
3
|
def self.included(base)
|
|
4
4
|
update_conditions = lambda { update_index_with_instance_elastico }
|
|
5
5
|
destroy_instance = lambda { destroy_instance_in_elastic_search }
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
base.send :after_save, update_conditions
|
|
7
8
|
base.send :after_destroy, destroy_instance
|
|
8
9
|
base.send :after_touch, update_conditions
|
|
9
10
|
|
data/lib/elastico/client.rb
CHANGED
|
@@ -13,8 +13,6 @@ module Elastico
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def general_request(content=nil, url=self.elastico_url, options = { :hash_respond_wanted => :true })
|
|
16
|
-
|
|
17
|
-
logger.info("========== in post ")
|
|
18
16
|
RestClient.post(url, content, :content_type => :json, :accept => :json) do |response, request, result|
|
|
19
17
|
ret = JSON.pretty_generate(JSON.parse(response.to_str))
|
|
20
18
|
options[:hash_respond_wanted] ? JSON.parse(ret) : ret
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Elastico
|
|
2
|
+
module Import
|
|
3
|
+
def elastico_import_all
|
|
4
|
+
self.find_each do |instance|
|
|
5
|
+
result = instance.update_index_with_instance_elastico
|
|
6
|
+
logger.info result
|
|
7
|
+
end
|
|
8
|
+
puts "Index for #{self.name} has finished. Errors regarding specific instances have been logged."
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/elastico/index.rb
CHANGED
|
@@ -26,6 +26,11 @@ module Elastico
|
|
|
26
26
|
|
|
27
27
|
def elastico_type_name= type_name
|
|
28
28
|
@type_name = type_name
|
|
29
|
-
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# This method should be over written in the model that includes elastico
|
|
32
|
+
def prepare_elastico_settings_and_mappings_json
|
|
33
|
+
nil
|
|
34
|
+
end
|
|
30
35
|
end
|
|
31
36
|
end
|
data/lib/elastico/version.rb
CHANGED
data/lib/elastico.rb
CHANGED
|
@@ -4,7 +4,7 @@ require_relative "./elastico/callbacks"
|
|
|
4
4
|
require_relative "./elastico/index"
|
|
5
5
|
require_relative "./elastico/search"
|
|
6
6
|
require_relative "./elastico/client"
|
|
7
|
-
|
|
7
|
+
require_relative "./elastico/import"
|
|
8
8
|
|
|
9
9
|
module Elastico
|
|
10
10
|
def self.included(base)
|
|
@@ -12,6 +12,7 @@ module Elastico
|
|
|
12
12
|
base.extend Index
|
|
13
13
|
base.extend Search
|
|
14
14
|
base.extend Client
|
|
15
|
+
base.extend Import
|
|
15
16
|
|
|
16
17
|
base.send :include_callbacks
|
|
17
18
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elastico
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -77,6 +77,7 @@ files:
|
|
|
77
77
|
- lib/elastico/callbacks.rb
|
|
78
78
|
- lib/elastico/client.rb
|
|
79
79
|
- lib/elastico/configuration.rb
|
|
80
|
+
- lib/elastico/import.rb
|
|
80
81
|
- lib/elastico/index.rb
|
|
81
82
|
- lib/elastico/search.rb
|
|
82
83
|
- lib/elastico/version.rb
|