elastico 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +26 -11
- data/lib/elastico/callbacks.rb +6 -2
- data/lib/elastico/client.rb +0 -1
- data/lib/elastico/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -6,8 +6,10 @@ __Simple__. Elastico is built in a way so your configuration and usage is as sim
|
|
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
|
|
9
|
-
There is one reason for building it Simple and Full:
|
10
|
-
Elasticsearch community is large. Its supportive, and very helpful
|
9
|
+
There is one main reason for building it Simple and Full:
|
10
|
+
Elasticsearch community is large. Its supportive, and very helpful, though most of it does not use ruby. Its most likely that you want to spend your time on feaguring out how to use elasticsearch rather than how to use the gem that works with elasticsearch. If you use Elastico, its most likely that your time will go to the former, and will be able to take advantage of the elasticsearch community.
|
11
|
+
|
12
|
+
|
11
13
|
|
12
14
|
You should give Elastico a try if you want to use elasticsearch full api.
|
13
15
|
|
@@ -49,19 +51,30 @@ Or install it yourself as:
|
|
49
51
|
In your model:
|
50
52
|
|
51
53
|
class Apple < ActiveRecord::Base
|
52
|
-
include Elastico
|
53
|
-
attr_accessible :color, :name
|
54
54
|
|
55
|
+
attr_accessible :color, :name
|
56
|
+
|
55
57
|
def self.prepare_elastico_settings_and_mappings_json
|
56
|
-
json = { "
|
58
|
+
json = { "settings" =>
|
57
59
|
{
|
58
|
-
"
|
60
|
+
"number_of_shards" => 3
|
61
|
+
},
|
62
|
+
"mappings" =>
|
63
|
+
{
|
64
|
+
"apple" =>
|
59
65
|
{
|
60
|
-
"
|
61
|
-
|
66
|
+
"properties" =>
|
67
|
+
{
|
68
|
+
"name" => {"type" => "string"},
|
69
|
+
"color" => {"type" => "string"}
|
70
|
+
}
|
62
71
|
}
|
63
|
-
|
64
|
-
|
72
|
+
}
|
73
|
+
}.to_json
|
74
|
+
end
|
75
|
+
|
76
|
+
# include elastico only after you declared your settings and mappings json in the method prepare_elastico_settings_and_mappings_json
|
77
|
+
include Elastico
|
65
78
|
end
|
66
79
|
|
67
80
|
|
@@ -118,11 +131,13 @@ __Optional__
|
|
118
131
|
|
119
132
|
4. Run Apple.elastico_import_all to import all your data.
|
120
133
|
|
134
|
+
5. Controll what fields are indexed by declaring a method called 'elastico_to_indexed_json'.
|
135
|
+
|
121
136
|
Use it.
|
122
137
|
-------
|
123
138
|
1. After every save Elastico will automatically save your instance in elasticsearch.
|
124
139
|
|
125
|
-
2. Import current database
|
140
|
+
2. Import current database by Apple.elastico_import_all.
|
126
141
|
|
127
142
|
3. Search it: call Apple.elastico_search to get your results, or override it to better suit your needs.
|
128
143
|
|
data/lib/elastico/callbacks.rb
CHANGED
@@ -9,7 +9,7 @@ module Elastico
|
|
9
9
|
base.send :after_touch, update_conditions
|
10
10
|
|
11
11
|
base.send :settings_and_mappings_json=, base.prepare_elastico_settings_and_mappings_json
|
12
|
-
base.send :send_settings_mappings_to_elasticsearch_server
|
12
|
+
# base.send :send_settings_mappings_to_elasticsearch_server
|
13
13
|
end
|
14
14
|
|
15
15
|
def update_index_with_instance_elastico
|
@@ -17,7 +17,11 @@ module Elastico
|
|
17
17
|
index = self.class.elastico_index_name
|
18
18
|
id = self.id
|
19
19
|
url = self.class.elastico_url + index + "/" + type + "/" + id.to_s
|
20
|
-
|
20
|
+
if self.respond_to? :elastico_to_indexed_json
|
21
|
+
instance = self.elastico_to_indexed_json
|
22
|
+
else
|
23
|
+
instance = self.to_json
|
24
|
+
end
|
21
25
|
self.class.general_request(instance, url)
|
22
26
|
end
|
23
27
|
|
data/lib/elastico/client.rb
CHANGED
@@ -2,7 +2,6 @@ module Elastico
|
|
2
2
|
module Client
|
3
3
|
def send_settings_mappings_to_elasticsearch_server
|
4
4
|
to_url = self.elastico_url + self.elastico_index_name
|
5
|
-
puts to_url
|
6
5
|
RestClient.put(to_url, self.settings_and_mappings_json, :content_type => :json, :accept => :json) do |response, request, result|
|
7
6
|
puts JSON.pretty_generate(JSON.parse(response.to_str))
|
8
7
|
end
|
data/lib/elastico/version.rb
CHANGED
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.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|