# Access to SearchSourceBuilder sourceBuilder for debugging

**URL:** <https://discuss.elastic.co/t/access-to-searchsourcebuilder-sourcebuilder-for-debugging/3335>\
**Category:** Elasticsearch\
**Created:** [September 14, 2010, 9:55pm UTC](https://discuss.elastic.co/t/access-to-searchsourcebuilder-sourcebuilder-for-debugging/3335 "2010-09-14T21:55:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [September 14, 2010, 9:55pm UTC](https://discuss.elastic.co/t/access-to-searchsourcebuilder-sourcebuilder-for-debugging/3335/1 "2010-09-14T21:55:16Z")

</div>

Hey,  
Currently using the Java API and am building up a  
SearchRequestBuilder object. I see that internally,  
SearchRequestBuilder keeps a SearchSourceBuilder member(sourceBuilder)  
that is private.

I would like to be able to provide some debug logging that would allow  
a developer to copy and paste a curl command to run a query and debug.  
In order to do this, I am currently instantiating my own  
SearchSourceBuilder and calling the methods on it that  
SearchRequestBuilder calls on its own internal sourceBuilder.

Afterwards, I instantiate a BinaryXContentBuilder and populate it with  
a call like this:  
BinaryXContentBuilder content = jsonBuilder();  
debugSearchSource.toXContent(content, null);

And finally, get the search json with a call like:  
content.string();

Is there anyway to get access to the SearchRequestBuilder's  
sourceBuilder, so I don't have to mirror the method calls to my copy  
or is there a better way to accomplish this that I have overlooked? A  
debug method to get the SearchRequestBuilder sourceBuilder as string  
or similar would be convenient for this case.

Thanks,  
Paul

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [September 15, 2010, 10:44am UTC](https://discuss.elastic.co/t/access-to-searchsourcebuilder-sourcebuilder-for-debugging/3335/2 "2010-09-15T10:44:11Z")

</div>

Pushed SearchRequestBuilder#internalBuilder(). Note, this should only be  
used in debug mode, and only make sense when generation json and not the  
binary smile format (on it I will post in a minute).

-shay.banon

On Tue, Sep 14, 2010 at 11:55 PM, Paul [ppearcy@gmail.com](mailto:ppearcy@gmail.com) wrote:

> Hey,  
> Currently using the Java API and am building up a  
> SearchRequestBuilder object. I see that internally,  
> SearchRequestBuilder keeps a SearchSourceBuilder member(sourceBuilder)  
> that is private.
> 
> I would like to be able to provide some debug logging that would allow  
> a developer to copy and paste a curl command to run a query and debug.  
> In order to do this, I am currently instantiating my own  
> SearchSourceBuilder and calling the methods on it that  
> SearchRequestBuilder calls on its own internal sourceBuilder.
> 
> Afterwards, I instantiate a BinaryXContentBuilder and populate it with  
> a call like this:  
> BinaryXContentBuilder content = jsonBuilder();  
> debugSearchSource.toXContent(content, null);
> 
> And finally, get the search json with a call like:  
> content.string();
> 
> Is there anyway to get access to the SearchRequestBuilder's  
> sourceBuilder, so I don't have to mirror the method calls to my copy  
> or is there a better way to accomplish this that I have overlooked? A  
> debug method to get the SearchRequestBuilder sourceBuilder as string  
> or similar would be convenient for this case.
> 
> Thanks,  
> Paul

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [September 15, 2010, 3:14pm UTC](https://discuss.elastic.co/t/access-to-searchsourcebuilder-sourcebuilder-for-debugging/3335/3 "2010-09-15T15:14:38Z")

</div>

Great, thanks!

On Sep 15, 4:44 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Pushed SearchRequestBuilder#internalBuilder(). Note, this should only be  
> used in debug mode, and only make sense when generation json and not the  
> binary smile format (on it I will post in a minute).
> 
> -shay.banon
> 
> On Tue, Sep 14, 2010 at 11:55 PM, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> 
> > Hey,  
> > Currently using the Java API and am building up a  
> > SearchRequestBuilder object. I see that internally,  
> > SearchRequestBuilder keeps a SearchSourceBuilder member(sourceBuilder)  
> > that is private.
> 
> > I would like to be able to provide some debug logging that would allow  
> > a developer to copy and paste a curl command to run a query and debug.  
> > In order to do this, I am currently instantiating my own  
> > SearchSourceBuilder and calling the methods on it that  
> > SearchRequestBuilder calls on its own internal sourceBuilder.
> 
> > Afterwards, I instantiate a BinaryXContentBuilder and populate it with  
> > a call like this:  
> > BinaryXContentBuilder content = jsonBuilder();  
> > debugSearchSource.toXContent(content, null);
> 
> > And finally, get the search json with a call like:  
> > content.string();
> 
> > Is there anyway to get access to the SearchRequestBuilder's  
> > sourceBuilder, so I don't have to mirror the method calls to my copy  
> > or is there a better way to accomplish this that I have overlooked? A  
> > debug method to get the SearchRequestBuilder sourceBuilder as string  
> > or similar would be convenient for this case.
> 
> > Thanks,  
> > Paul

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:19am UTC](https://discuss.elastic.co/t/access-to-searchsourcebuilder-sourcebuilder-for-debugging/3335/4 "2017-07-06T04:19:18Z")

</div>


