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;

@miguelgrinberg miguelgrinberg force-pushed the esql-query-builder branch 2 times, most recently from b54a783 to c602ff7 Compare October 7, 2025 17:33
@miguelgrinberg miguelgrinberg marked this pull request as ready for review October 8, 2025 16:02
@miguelgrinberg miguelgrinberg requested a review from a team as a code owner October 8, 2025 16:02
@miguelgrinberg
Copy link
Author

miguelgrinberg commented Oct 8, 2025

@ezimuel This is ready to review!

Maybe what makes the most sense is for you to read the unit test file first, so that you see how all the commands are constructed.

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