-
Notifications
You must be signed in to change notification settings - Fork 981
ESQL query builder prototype #1462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@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 . |
|
@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; |
f1feaca to
82ae0fe
Compare
b54a783 to
c602ff7
Compare
c602ff7 to
85f63cc
Compare
|
@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. |
c586cb8 to
bee8abb
Compare
e3c1282 to
491b3b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @miguelgrinberg for this awesome PR! I just left a couple of comments, the most relevant that I would suggest to investigate is the possibility to use Traits instead of passing the parent in EsqlBase.
Moreover, we should add also some documentation about this helper with an example on how to call it using the Esql endpoint.
| /** | ||
| * Helper function that checks if a forking command has been issued already. | ||
| */ | ||
| protected function isForked(): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can avoid using this function and avoid to pass the parent reference for each class using a Trait here. I used this mechanism for code reuse in the AbstractEndpoint to share common code on each Endpoint implementation.
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:
Output:
In IDEs, you get correct suggestions based on context. For example: