Rewrote SuggestResponse#toString method
It only prints out json now (as the SearchResponse does) Added missing startObject & endObject (was causing JsonGenerationException) Closes #3661
This commit is contained in:
parent
0efa78710b
commit
0b79ba9493
|
@ -19,20 +19,19 @@
|
||||||
|
|
||||||
package org.elasticsearch.action.suggest;
|
package org.elasticsearch.action.suggest;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.elasticsearch.action.ShardOperationFailedException;
|
import org.elasticsearch.action.ShardOperationFailedException;
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse;
|
import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContent;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
|
||||||
import org.elasticsearch.search.suggest.Suggest;
|
import org.elasticsearch.search.suggest.Suggest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The response of the suggest action.
|
* The response of the suggest action.
|
||||||
*/
|
*/
|
||||||
|
@ -70,14 +69,14 @@ public final class SuggestResponse extends BroadcastOperationResponse {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String source;
|
|
||||||
try {
|
try {
|
||||||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
|
||||||
suggest.toXContent(builder, null);
|
builder.startObject();
|
||||||
source = XContentHelper.convertToJson(builder.bytes(), true);
|
suggest.toXContent(builder, EMPTY_PARAMS);
|
||||||
|
builder.endObject();
|
||||||
|
return builder.string();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
source = "Error: " + e.getMessage();
|
return "{ \"error\" : \"" + e.getMessage() + "\"}";
|
||||||
}
|
}
|
||||||
return "Suggest Response["+source+"]";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue