Skip to content

Conversation

miguelgrinberg
Copy link

@miguelgrinberg miguelgrinberg commented Sep 10, 2025

This PR contains a prototype of an ES|QL query builder feature for the PHP client based on the one I built for the Python client.

Example usage:

$query = Esql\Query::from("books", "books*")
    ->where('author == "King"', 'year == 1982')
    ->limit(10);
echo $query;

Output:

FROM books, books*
| WHERE author == "King" AND year == 1982
| LIMIT 10

In IDEs, you get correct suggestions based on context. For example:

Screenshot 2025-09-11 at 2 43 24 PM

@ezimuel
Copy link
Contributor

ezimuel commented Sep 10, 2025

@miguelgrinberg thanks for the PR it looks interesting. The only comment that I've at the moment is to split each class in a separate file. The name of the file must be the same of the class. This is a best practices in PHP .

@miguelgrinberg
Copy link
Author

miguelgrinberg commented Sep 11, 2025

@ezimuel I refactored into multiple files (one per class) and added a couple more commands now. Let me know if this structure seems reasonable and I'll add the remaining commands and all the docs.

Two usage examples:

use Elastic\Elasticsearch\Helper\Esql;

$query = Esql\Query::from("books", "books*")
    ->where('author == "King"', 'year == 1982')
    ->limit(10);
echo $query;

$query = Esql\Query::row(a: 123, b: "test")
    ->limit(1);
echo $query;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants