spameri / elastic-query
Objects instead of arrays for querying to ElasticSearch.
Installs: 41 867
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 4
Open Issues: 1
pkg:composer/spameri/elastic-query
Requires
- php: >=8.2
- ext-json: *
Requires (Dev)
- ext-curl: *
- elasticsearch/elasticsearch: ^7
- guzzlehttp/guzzle: ^6.3
- nette/tester: v2.3.1
- phpstan/phpstan: ^1.11.3
- slevomat/coding-standard: ^8.0
- dev-master
- v2.x-dev
- v2.0.0-alpha.3
- v2.0.0-alpha.2
- v2.0.0-alpha
- v1.0.1
- v1.0.0
- v1.0.0-alpha.20
- v1.0.0-alpha.19
- v1.0.0-alpha.18
- v1.0.0-alpha.17
- v1.0.0-alpha.16
- v1.0.0-alpha.15
- v1.0.0-alpha.14
- v1.0.0-alpha.13
- v1.0.0-alpha.12
- v1.0.0-alpha.11
- v1.0.0-alpha.10
- v1.0.0-alpha.9
- v1.0.0-alpha.8
- v1.0.0-alpha.7
- v1.0.0-alpha.6
- v1.0.0-alpha.5
- v1.0.0-alpha.4
- v1.0.0-alpha.3
- v1.0.0-alpha.2
- v1.0.0-alpha
- v0.6.0
- v0.6.0-beta
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.2
- v0.1.1
- v0.1.0
- dev-version-one
This package is auto-updated.
Last update: 2025-12-23 00:56:52 UTC
README
A PHP library that converts Elasticsearch query DSL into strongly-typed PHP objects. Instead of building queries as arrays, use type-safe classes that mirror the Elasticsearch documentation.
Features
- Type-safe queries - Full-text, term-level, compound, geo, and nested queries
- Aggregations - Metric (min, max, avg) and bucket (terms, histogram, range, filter) aggregations
- Response mapping - Automatic mapping of Elasticsearch responses to typed objects
- Index mapping - Define index settings, analyzers, tokenizers, and filters
- Function scoring - Custom scoring with field value factors, weights, and random scores
- Highlighting - Search result highlighting support
- Pagination & sorting - Options for size, offset, scroll, and geo-distance sorting
Requirements
- PHP 8.2 or higher
Installation
Install via Composer:
composer require spameri/elastic-query
Quick Start
use Spameri\ElasticQuery\ElasticQuery; use Spameri\ElasticQuery\Query\ElasticMatch; use Spameri\ElasticQuery\Query\Term; // Create a query $query = new ElasticQuery(); // Add a must query (AND condition) $query->addMustQuery(new ElasticMatch('title', 'Elasticsearch')); // Add a filter (cached, no scoring) $query->addFilter(new Term('status', 'published')); // Set pagination $query->options()->changeSize(10); $query->options()->changeFrom(0); // Convert to array for Elasticsearch client $body = $query->toArray();
Documentation
Learn more in the documentation:
- Usage - Integration examples
- Query Objects - All query types
- Aggregation Objects - Aggregation types
- Result Objects - Response mapping
- Options & Sorting - Pagination, sorting, scroll
- Highlight & Function Score - Highlighting and custom scoring
- Mapping & Settings - Index configuration
License
MIT