Any way to see json representation of request constructed with SearchRequestBuilder?

I'm trying to use the java api to construct a search request, and I'm
encountering problems. Unfortunately, I have no idea what's causing
them, because I can't find a way to see what query is actually getting
constructed. Is there some way I can see the actual json that the
SearchRequestBuilder gets converted into, so I can debug my query?

There isn't a simple toString method (I'll add it). You can call SearchRequestBuilder#internalBuilder().buildAsBytes(XContentType.JSON).
On Friday, May 13, 2011 at 11:28 PM, Ellery Crane wrote:

I'm trying to use the java api to construct a search request, and I'm
encountering problems. Unfortunately, I have no idea what's causing
them, because I can't find a way to see what query is actually getting
constructed. Is there some way I can see the actual json that the
SearchRequestBuilder gets converted into, so I can debug my query?

Hi,
maybe you wanna try this:

XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
XContentBuilder toXContent = queryBuilder.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
String query = toXContent.string();

where as queryBuilder is type of BaseQueryBuilder.

Thanks Shay! Though as a note to anyone else trying to do this, you'll
need to wrap the byte in a String:

String json = new
String(builder.internalBuilder().buildAsBytes(XContentType.JSON));

On May 14, 7:48 am, Shay Banon shay.ba...@elasticsearch.com wrote:

There isn't a simple toString method (I'll add it). You can call SearchRequestBuilder#internalBuilder().buildAsBytes(XContentType.JSON).

On Friday, May 13, 2011 at 11:28 PM, Ellery Crane wrote:

I'm trying to use the java api to construct a search request, and I'm
encountering problems. Unfortunately, I have no idea what's causing
them, because I can't find a way to see what query is actually getting
constructed. Is there some way I can see the actual json that the
SearchRequestBuilder gets converted into, so I can debug my query?

Yes, though make sure to use UTF8 charset. There is a toString method now in master.
On Monday, May 16, 2011 at 6:01 PM, Ellery Crane wrote:

Thanks Shay! Though as a note to anyone else trying to do this, you'll
need to wrap the byte in a String:

String json = new
String(builder.internalBuilder().buildAsBytes(XContentType.JSON));

On May 14, 7:48 am, Shay Banon shay.ba...@elasticsearch.com wrote:

There isn't a simple toString method (I'll add it). You can call SearchRequestBuilder#internalBuilder().buildAsBytes(XContentType.JSON).

On Friday, May 13, 2011 at 11:28 PM, Ellery Crane wrote:

I'm trying to use the java api to construct a search request, and I'm
encountering problems. Unfortunately, I have no idea what's causing
them, because I can't find a way to see what query is actually getting
constructed. Is there some way I can see the actual json that the
SearchRequestBuilder gets converted into, so I can debug my query?