Ruby Client
The Ruby client wraps hlquery's HTTP API with a small Ruby interface for scripts, services, internal tools, and test automation.
Installation
For local usage from this repository:
$LOAD_PATH.unshift(File.expand_path("lib", __dir__))
require "hlquery"
Create a Client
client = Hlquery::Client.new(
ENV["HLQ_BASE_URL"] || ENV["HLQUERY_BASE_URL"] || "http://localhost:9200"
)
With authentication:
client = Hlquery::Client.new("http://localhost:9200", {
token: ENV["HLQ_TOKEN"],
auth_method: "bearer"
})
client.set_auth_token("api-key-value", "api-key")
Basic Usage
health = client.health
puts health.body.inspect if health.success?
collections = client.list_collections(0, 10)
puts collections.body.inspect
Search
results = client.search("products", {
"q" => "waterproof jacket",
"query_by" => "title,description",
"limit" => 10
})
If q is set and query_by is omitted, the client attempts to infer searchable fields from the collection metadata.
Examples
Repository examples live in etc/api/ruby/examples:
basic_usage.rbcollections.rbdocuments.rbsearch.rbvector.rb