erichard/elasticsearch-query-builder
A fluent PHP query builder for Elasticsearch that lets you construct complex search queries through an elegant, chainable API instead of hand-writing JSON. A good fit for Laravel and standalone PHP projects that need readable, maintainable Elasticsearch DSL.
Architecture fit. erichard/elasticsearch-query-builder is a narrow, well-bounded utility: it turns Elasticsearch query DSL into a fluent PHP API instead of hand-assembled nested arrays. It is a builder, not a client, ORM, or index-management layer, so it sits cleanly between domain/service code and the official elasticsearch-php client. Architectural footprint is low and additive. The value proposition is developer ergonomics and readability of complex queries; if our codebase already has an internal query-composition helper or only issues trivial queries, the marginal benefit is small.
Integration feasibility. Composer-installable, MIT-licensed, PHP library with a release cut in June 2024. Integration cost should be low — likely composer require plus a short spike, with no Laravel service provider or config surface required (it appears framework-agnostic). Feasibility hinges on version compatibility (PHP constraint, elasticsearch-php major version, ES server version) rather than on any deep coupling.
Technical risk. The dominant risk is project vitality, not engineering complexity:
Key questions.
elasticsearch-php and Elasticsearch server versions do we target, and does the builder support them (ES 7 vs. 8 typeless APIs)?Stack fit. PHP/Laravel with Composer and PSR-4 autoloading is a native fit. The builder emits plain query arrays that are handed to the official client, so it composes with existing HTTP, queue, and Octane concerns and is stateless by nature. It does not contend with Laravel's own facilities and should not require service-provider registration.
Migration path. Adopt behind an internal seam: define our own QueryBuilder interface (or thin facade) and let this package be one implementation. Migrate incrementally — use it for new queries and read paths; leave existing raw-array queries untouched until they are next modified. Avoid a big-bang rewrite of working search code, and keep the abstraction so swapping to raw arrays, a fork, or a different builder is a contained change.
Compatibility. Confirm, in this order: PHP runtime constraint → elasticsearch-php major version → Elasticsearch server version → supported DSL features. Pin versions in composer.json, run composer why-not during upgrades, and add a contract test that exercises representative queries against a real (containerized) Elasticsearch in CI so client/server drift is caught early.
Sequencing.
Maintenance. The code we own is tiny, but the dependency is not zero-cost: we must track upstream releases, elasticsearch-php bumps, and Elasticsearch DSL drift. Assign a named owner and a periodic review (e.g., quarterly). Maintain a fork/patched-fork contingency — MIT permits this — and record the currently supported version in an ADR.
Support. Community-only, no SLA. Issue responsiveness may be slow or absent, so we absorb the support burden. Document an internal escalation path: pin a known-good version, patch locally in a fork if needed, and treat the internal wrapper as the stable contract for product teams.
Scaling. The builder is not a runtime bottleneck — constructing arrays is negligible CPU/memory and has no connection or pooling behavior. Real scaling risk lives in the query patterns it encourages (deep pagination, large aggregations, unbounded result sets) and in the Elasticsearch cluster itself. Enforce query-shape guardrails (size limits, pagination strategy, aggregation caps) in the wrapper rather than relying on the package.
Failure modes. Watch for: runtime errors from unsupported DSL constructs; silent semantic mis-compilation (e.g., incorrect bool nesting) producing wrong or empty results; breakage after an ES or client upgrade; dependency-resolution conflicts; and abandonment leaving unpatched issues. Mitigate with golden-query contract tests against real Elasticsearch, version pinning, and the abstraction seam that keeps a swap cheap.
Ramp-up. The fluent API is small; a PHP developer should be productive within a day. The real learning curve is Elasticsearch DSL literacy, which the package does not remove. Provide vetted examples and an ADR describing the supported subset; training cost is low, domain-knowledge cost is moderate.
How can I help you explore Laravel packages today?