Module: S3Browser::Store::StorePlugins::ES::InstanceMethods
- Defined in:
- lib/s3browser/plugins/es.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
- #add(bucket, object) ⇒ Object
- #buckets ⇒ Object
- #indices ⇒ Object
- #initialize(index) ⇒ Object
- #object(bucket, key) ⇒ Object
- #objects(bucket, options) ⇒ Object
- #remove(bucket, key) ⇒ Object
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
13 14 15 |
# File 'lib/s3browser/plugins/es.rb', line 13 def index @index end |
Instance Method Details
#add(bucket, object) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/s3browser/plugins/es.rb', line 20 def add(bucket, object) # TODO Can be optimized to do a bulk index every X requests object[:bucket] = bucket object[:last_modified] = object[:last_modified].to_i object[:url] = "#{object_url}/#{bucket}/#{object[:key]}" client.index(index: index, type: 'objects', id: object[:key], body: object) super(bucket, object) end |
#buckets ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/s3browser/plugins/es.rb', line 44 def buckets buckets = client.search(index: index, type: 'objects', body: { query: { match_all: {} }, size: 0, aggregations: { buckets: { terms: { field: :bucket, size: 0, order: { '_term' => :asc } } } } })['aggregations']['buckets']['buckets'].map {|val| val['key'] } return buckets unless buckets.empty? super end |
#indices ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/s3browser/plugins/es.rb', line 62 def indices lines = client.cat.indices lines.split("\n").map do |line| line = Hash[*[ :health, :state, :index, :primaries , :replicas, :count, :deleted, :total_size, :size ].zip(line.split(' ')).flatten] [:primaries, :replicas, :count, :deleted].each {|key| line[key] = line[key].to_i} line end end |
#initialize(index) ⇒ Object
15 16 17 18 |
# File 'lib/s3browser/plugins/es.rb', line 15 def initialize(index) @index = index check_index end |
#object(bucket, key) ⇒ Object
39 40 41 42 |
# File 'lib/s3browser/plugins/es.rb', line 39 def object(bucket, key) result = client.get(index: index, type: 'objects', id: key) result['_source'].inject({}){|memo,(k,v)| memo[k.downcase.to_sym] = v; memo} end |
#objects(bucket, options) ⇒ Object
34 35 36 37 |
# File 'lib/s3browser/plugins/es.rb', line 34 def objects(bucket, ) result = client.search(index: index, type: 'objects', body: search_body(bucket, )) result['hits']['hits'].map {|val| val['_source'].inject({}){|memo,(k,v)| memo[k.downcase.to_sym] = v; memo} } end |
#remove(bucket, key) ⇒ Object
29 30 31 32 |
# File 'lib/s3browser/plugins/es.rb', line 29 def remove(bucket, key) client.delete(index: index, type: 'objects', id: key, ignore: [404]) super(bucket, key) end |