Client Examples
The repository includes runnable examples beside every bundled client. Start
hlquery on port 9200, then run an example from the repository root.
Quick commands
| Language | Command | More examples |
|---|---|---|
| C++ | cd etc/api/cpp && make && ./basic_usage | C++ examples |
| Go | cd etc/api/go && go run ./examples/basic_usage | Go examples |
| Java | cd etc/api/java && make example | Java examples |
| Node.js | cd etc/api/node && npm install && node examples/basic_usage.js | Node.js examples |
| Python | cd etc/api/python && python3 examples/basic_usage.py | Python examples |
| PHP | cd etc/api/php && php examples/basic_usage.php | PHP examples |
| Perl | cd etc/api/perl && perl examples/basic_usage.pl | Perl examples |
| Rust | cd etc/api/rust && cargo run --example basic_usage | Rust examples |
| Ruby | cd etc/api/ruby && ruby example.rb | Ruby client |
The TypeScript package and examples are covered in the TypeScript client guide.
Pick an example by task
Most client folders use the same names:
basic_usagechecks connectivity and introduces response handling.collectionscreates, lists, inspects, and removes schemas.documentsdemonstrates CRUD and imports.searchcovers query options, filters, sorting, and facets.sqlruns SQL-style selection or aggregation.flushdemonstrates the administrative flush operation.vectoris present in clients with vector helpers.keysis present in clients with API-key management helpers.
Not every SDK implements every example. Use the linked language page as the source of truth for the currently bundled files.
Node.js service example
const Client = require('./lib/Client');
const client = new Client('http://localhost:9200', {
token: process.env.HLQUERY_API_KEY,
auth_method: 'api-key',
timeout: 5000
});
async function findProducts(q) {
const response = await client.search('products', {
q,
query_by: 'title,description',
filter_by: 'in_stock:true',
limit: 10
});
if (!response.isSuccess()) {
throw new Error(response.getError() || 'hlquery search failed');
}
return response.getBody().hits ?? [];
}
Python script example
import os
from lib import Client
client = Client('http://localhost:9200', {
'token': os.environ.get('HLQUERY_API_KEY'),
'auth_method': 'api-key',
})
response = client.search('products', {
'q': 'keyboard',
'query_by': 'title,description',
'filter_by': 'in_stock:true',
'limit': 10,
})
if not response.is_success():
raise RuntimeError(response.get_error())
for hit in response.get_body().get('hits', []):
print(hit['document']['title'])
Raw HTTP remains useful
Client libraries wrap the same HTTP API. When a new server route is not yet
available as a typed helper, use the client's low-level request method or a
small raw HTTP call, then return to the typed helper after SDK support lands.
This is also a useful way to compare an SDK request with a working curl
recipe while debugging.