Introducing OpenSearch DSL library to provide objective query builder for opensearch-php client. You can easily build any Opensearch query and transform it to an array.
This is a fork of ongr-io/ElasticsearchDSL, which will be more regularly updated. Thanks for ongr-io for building this Library!
If you need any help, Github issues is the preferred and recommended way to ask support questions.
| OpenSearch version | OpenSearchDSL version |
|---|---|
| >= 1.0 | >= 1.0 |
| >= 2.0 | >= 1.0 |
- User Guide - Comprehensive guide with examples for building queries, aggregations, sorting, and more
- API Documentation - Detailed reference documentation
Install library with composer:
composer require shyim/opensearch-php-dslNote: This library does not require
elasticsearch/elasticsearchoropensearch-project/opensearch-php. It is a standalone query builder that generates arrays compatible with any OpenSearch client.
<?php
require 'vendor/autoload.php';
use OpenSearchDSL\Search;
use OpenSearchDSL\Query\MatchAllQuery;
$search = new Search();
$search->addQuery(new MatchAllQuery());
$params = [
'index' => 'your_index',
'body' => $search->toArray(),
];
// Use with opensearch-php client
$client = \OpenSearch\ClientBuilder::create()->build();
$results = $client->search($params);- Query Building: Support for all OpenSearch query types (match, term, range, bool, geo, etc.)
- Aggregations: Bucket, metric, and pipeline aggregations
- Sorting: Field sorting with multiple criteria
- Highlighting: Search result highlighting
- Suggestions: Term, phrase, and completion suggesters
- Framework Agnostic: Works with any HTTP client or OpenSearch client library
For detailed examples and usage instructions, see the User Guide.