class LogStash::Filters::Empow::PersistentKeyValueDB
Public Class Methods
new(hosts, username, password, index)
click to toggle source
include LogStash::Util::Loggable
# File lib/logstash/filters/elastic-db.rb, line 8 def initialize(hosts, username, password, index) #@logger ||= self.logger #@logger.debug("opening the local classification db") @elastic ||= Elasticsearch::Client.new(:hosts => hosts) @index = index create_index index end
Public Instance Methods
close()
click to toggle source
# File lib/logstash/filters/elastic-db.rb, line 104 def close #@logger.debug("clsoing the local classification db") end
create_index(index)
click to toggle source
# File lib/logstash/filters/elastic-db.rb, line 19 def create_index(index) return if @elastic.indices.exists? index: index @elastic.indices.create index: index, body: { mappings: { _doc: { properties: { product_type: { type: 'keyword' }, product: { type: 'keyword' }, term_key: { type: 'keyword' }, classification: { enabled: false } } } } } end
query(product_type, product, term)
click to toggle source
# File lib/logstash/filters/elastic-db.rb, line 44 def query(product_type, product, term) #@logger.debug("quering local classification db") # fix nil product if product.nil? product = 'nil_safe_product_key' end response = @elastic.search index: @index, type: '_doc', body: { query: { bool: { must: [ { term: { product_type: product_type } }, { bool: { should: [ { bool: { must: [ { term: { term_key: term } }, { term: { product: product } } ] } }, { bool: { must: { term: { term_key: term } }, must_not: { exists: { field: 'product' } } } } ] } } ] } } } mash = Hashie::Mash.new response return nil if mash.hits.hits.first.nil? return mash.hits.hits.first._source.classification end
save(doc_id, product_type, product, term, classification)
click to toggle source
# File lib/logstash/filters/elastic-db.rb, line 93 def save(doc_id, product_type, product, term, classification) #@logger.debug("saving key to local classification db") @elastic.index index: @index, type: '_doc', id: doc_id, body: { product_type: product_type, product: product, term_key: term, classification: classification } end