Elastica
Elastica copied to clipboard
[DX] Add __toString to Query
It would make debugging usage much easier if we could just echo the query object and have it return a query ready for using directly with Postman, say:
public function __toString()
{
return json_encode($this->toArray(), JSON_PRETTY_PRINT);
}
Happy to add magical methods if it helps debugging and does not have side effects. Want to open a PR? I wonder if we should add this directly in the Param object so all other objects would inherit it.
Want to open a PR?
Sounds easy enough. :+1:
I wonder if we should add this directly in the Param object so all other objects would inherit it.
My usual workflow here was to have a custom query built by hand and trying to rebuild it using query builder or such. Param is OK too, but as you can't just paste it to a ES shell to verify it's valid, don't see the value other than easier visual inspection. But, that sounds valid too, now that I think about it.
You have much more experience, you decide.
I really like the idea to be able to paste it to the kibana dev tools. I remember we had in the past a logger that was writing almost that format.
The reason I suggest Param because having the raw object is not only useful for Query, but also for Search, Snapshot any many others I assume. But to make it useful for the Dev Tools, it needs to have a path too.
Let's start experimenting with Query/Search first and have a __toString() method there. Could you modify your proposal above that it is indeed copy/paste to the dev tools including the path and method? Or do you think that is too much?
This idea is really interesting, from a development pov is really usefull having such method that allow to test directly the query inside ES.
Can you explain more?