Elastica icon indicating copy to clipboard operation
Elastica copied to clipboard

[DX] Add __toString to Query

Open dkarlovi opened this issue 6 years ago • 5 comments

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);
}

dkarlovi avatar Apr 05 '18 09:04 dkarlovi

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.

ruflin avatar Apr 06 '18 07:04 ruflin

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.

dkarlovi avatar Apr 06 '18 08:04 dkarlovi

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?

ruflin avatar Apr 06 '18 12:04 ruflin

This idea is really interesting, from a development pov is really usefull having such method that allow to test directly the query inside ES.

p365labs avatar Nov 19 '18 10:11 p365labs

Can you explain more?

netwons avatar Nov 16 '19 11:11 netwons