es_query_builder 1.0.0 → 1.0.1
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/{housing_es_query_builder.rb → es_query_builder.rb} +1 -1
- data/lib/indexer.rb +59 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9918de99eda2a0fa724460dd616cb87315be0327
|
4
|
+
data.tar.gz: c0a46413dab8cee197f1e800f7d8df486de40304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 115887d20ce20b7d85e3c267e407b989cff208b369f756de4c668a755cfab26dc6b6be908b59cf911ec1d4eab38f22fe89bb51e962e4897f41d5275fce55b14c
|
7
|
+
data.tar.gz: 489259d05b3a7356f6d881bac267776bb4becc58466ddf4bb4fba15a762b978b7f8fb9e69b1c57ec3599aff3481a6c60bc3311c6d2cd0cdc4b9f5931527d08af
|
data/lib/indexer.rb
CHANGED
@@ -37,7 +37,7 @@ class Indexer
|
|
37
37
|
# deletes the record if exists in the given index with given type and id,
|
38
38
|
# raises DocumentNotFoundException if record is not found
|
39
39
|
# @param index_name [String] name of the index
|
40
|
-
# @param
|
40
|
+
# @param index_type [String] name of the type
|
41
41
|
# @param id [String] doc_id
|
42
42
|
# @param parent_id [String] parent_id
|
43
43
|
def delete_record(index_name, type_name, id, parent_id = nil)
|
@@ -46,6 +46,64 @@ class Indexer
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
# switches to new index ,will be used when doing bulk caching
|
50
|
+
# @param new_index [String] name of the index(with timestamp)
|
51
|
+
# @param alias name , name with which you refer to fetch index details
|
52
|
+
# @param old_index_delete_flag, bool value to decide whether to keep last index or delete it
|
53
|
+
def switch_to_new_index(new_index, alias_name, old_index_delete_flag = true)
|
54
|
+
begin
|
55
|
+
result = @client.indices.get_alias name: "#{alias_name}"
|
56
|
+
rescue Exception => e
|
57
|
+
puts "#{e.exception}"
|
58
|
+
if e.class == Elasticsearch::Transport::Transport::Errors::NotFound
|
59
|
+
result = nil
|
60
|
+
else
|
61
|
+
raise NameError,"#{e}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
unless result.nil?
|
65
|
+
if result.keys.count > 1
|
66
|
+
raise NameError,"Multiple indexes found for alias #{alias_name}"
|
67
|
+
else
|
68
|
+
old_index = result.keys.first
|
69
|
+
log_file = Logger.new("log/old_index.log")
|
70
|
+
log_file.info("old_index - #{old_index}")
|
71
|
+
@client.indices.update_aliases body: {
|
72
|
+
actions: [
|
73
|
+
{ remove: { index: "#{old_index}", alias: "#{alias_name}" } },
|
74
|
+
{ add: { index: "#{new_index}", alias: "#{alias_name}" } }
|
75
|
+
]
|
76
|
+
}
|
77
|
+
if old_index_delete_flag
|
78
|
+
@client.indices.delete index: "#{old_index}"
|
79
|
+
else
|
80
|
+
@client.indices.close index: "#{old_index}"
|
81
|
+
end
|
82
|
+
message = old_index_delete_flag ? "index swapping done #{old_index} deleted and " : ""
|
83
|
+
message += "#{new_index} created"
|
84
|
+
puts message
|
85
|
+
end
|
86
|
+
else
|
87
|
+
## checks if index exists with the name of alias itself and handles accordingly.
|
88
|
+
if @client.indices.exists(index: "#{alias_name}") && old_index_delete_flag
|
89
|
+
@client.indices.delete index: "#{alias_name}"
|
90
|
+
puts "#{alias_name} index deleted"
|
91
|
+
end
|
92
|
+
puts "Alias #{alias_name} set for new index #{new_index} "
|
93
|
+
@client.indices.put_alias index: "#{new_index}", name: "#{alias_name}"
|
94
|
+
end
|
95
|
+
puts "#{new_index} set up"
|
96
|
+
end
|
97
|
+
|
98
|
+
# creates new index givem the mapping and settings in index_params_hash
|
99
|
+
# @param index_name [String] name of the index(with timestamp)
|
100
|
+
# @param index_type [String] name of the type
|
101
|
+
# @param index_params_hash, {settins:{},mappings:{}}
|
102
|
+
def create_index(index_name, index_type, index_params_hash)
|
103
|
+
@client.indices.create index: "#{index_name}",
|
104
|
+
type: "#{index_type}",
|
105
|
+
body: index_params_hash
|
106
|
+
end
|
49
107
|
|
50
108
|
private
|
51
109
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es_query_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mohib Yousuf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,8 +52,8 @@ extra_rdoc_files: []
|
|
52
52
|
files:
|
53
53
|
- lib/constants.rb
|
54
54
|
- lib/elastic_search_query.rb
|
55
|
+
- lib/es_query_builder.rb
|
55
56
|
- lib/fetch_es_data.rb
|
56
|
-
- lib/housing_es_query_builder.rb
|
57
57
|
- lib/indexer.rb
|
58
58
|
- lib/token_query_builder.rb
|
59
59
|
homepage: https://github.com/elarahq/es.query.builder
|