Class: ElasticSearch::Client
- Inherits:
-
Object
- Object
- ElasticSearch::Client
- Defined in:
- lib/jruby-elasticsearch/client.rb
Instance Method Summary collapse
- #bulk ⇒ Object
- #bulkstream(queue_size = 10, flush_interval = 1) ⇒ Object
-
#cluster ⇒ Object
def search.
-
#index(index, type, id = nil, data = {}, &block) ⇒ Object
Index a new document.
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new ElasticSearch client.
- #node ⇒ Object
- #search(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new ElasticSearch client.
options: :type => [:local, :node] - :local will create a process-local
elasticsearch instances
:host => “hostname” - the hostname to connect to. :port => 9200 - the port to connect to :cluster => “clustername” - the cluster name to use
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jruby-elasticsearch/client.rb', line 16 def initialize(={}) builder = org.elasticsearch.node.NodeBuilder.nodeBuilder builder.client(true) # The client doesn't need to serve http builder.settings.put("http.enabled", false) case [:type] when :local builder.local(true) @node = builder.node @client = @node.client when :transport # TODO(sissel): Support transport client else # Use unicast discovery a host is given if ![:host].nil? port = ([:port] or "9300") builder.settings.put("discovery.zen.ping.multicast.enabled", false) builder.settings.put("discovery.zen.ping.unicast.hosts", "#{[:host]}:#{port}") #builder.settings.put("es.transport.tcp.port", port) end if [:bind_host] builder.settings.put('network.host', [:bind_host]) end if ![:cluster].nil? builder.clusterName([:cluster]) end @node = builder.node @client = @node.client end end |
Instance Method Details
#bulk ⇒ Object
55 56 57 |
# File 'lib/jruby-elasticsearch/client.rb', line 55 def bulk return ElasticSearch::BulkRequest.new(@client) end |
#bulkstream(queue_size = 10, flush_interval = 1) ⇒ Object
60 61 62 |
# File 'lib/jruby-elasticsearch/client.rb', line 60 def bulkstream(queue_size=10, flush_interval=1) return ElasticSearch::BulkStream.new(self, queue_size, flush_interval) end |
#cluster ⇒ Object
def search
118 119 120 |
# File 'lib/jruby-elasticsearch/client.rb', line 118 def cluster return @client.admin.cluster end |
#index(index, type, id = nil, data = {}, &block) ⇒ Object
Index a new document
args:
index: the index name
type: the type name
id: (optional) the id of the document
data: (optional) the data for this document
&block: (optional) optional block for using the DSL to add data
Returns an ElasticSearch::IndexRequest instance.
Example w/ DSL:
request = client.index("foo", "logs") do
filename "/var/log/message"
mesage "hello world"
123456
end
request.execute!
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/jruby-elasticsearch/client.rb', line 84 def index(index, type, id=nil, data={}, &block) # Permit 'id' being omitted entirely. # Thus a call call: index("foo", "bar", somehash) is valid. if id.is_a?(Hash) data = id id = nil end indexreq = ElasticSearch::IndexRequest.new(@client, index, type, id, data) if block_given? indexreq.instance_eval(&block) end return indexreq end |
#node ⇒ Object
122 123 124 |
# File 'lib/jruby-elasticsearch/client.rb', line 122 def node return @client.admin.cluster end |
#search(&block) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/jruby-elasticsearch/client.rb', line 110 def search(&block) searchreq = ElasticSearch::SearchRequest.new(@client) if block_given? searchreq.with(&block) end return searchreq end |