better handling of source return value based on content type (embed it if its the same content type)
This commit is contained in:
parent
34d99c39a5
commit
ceb0138aa8
|
@ -27,6 +27,7 @@ import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.rest.*;
|
import org.elasticsearch.rest.*;
|
||||||
import org.elasticsearch.util.guice.inject.Inject;
|
import org.elasticsearch.util.guice.inject.Inject;
|
||||||
import org.elasticsearch.util.settings.Settings;
|
import org.elasticsearch.util.settings.Settings;
|
||||||
|
import org.elasticsearch.util.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
|
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -87,7 +88,12 @@ public class RestGetAction extends BaseRestHandler {
|
||||||
builder.field("_type", response.type());
|
builder.field("_type", response.type());
|
||||||
builder.field("_id", response.id());
|
builder.field("_id", response.id());
|
||||||
if (response.source() != null) {
|
if (response.source() != null) {
|
||||||
builder.rawField("_source", response.source());
|
if (builder.contentType() == XContentFactory.xContentType(response.source())) {
|
||||||
|
builder.rawField("_source", response.source());
|
||||||
|
} else {
|
||||||
|
builder.field("_source");
|
||||||
|
builder.value(response.source());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.fields() != null && !response.fields().isEmpty()) {
|
if (response.fields() != null && !response.fields().isEmpty()) {
|
||||||
|
|
|
@ -206,10 +206,10 @@ public class InternalSearchHit implements SearchHit {
|
||||||
builder.field("_id", id());
|
builder.field("_id", id());
|
||||||
if (source() != null) {
|
if (source() != null) {
|
||||||
if (XContentFactory.xContentType(source()) == builder.contentType()) {
|
if (XContentFactory.xContentType(source()) == builder.contentType()) {
|
||||||
|
builder.rawField("_source", source());
|
||||||
|
} else {
|
||||||
builder.field("_source");
|
builder.field("_source");
|
||||||
builder.value(source());
|
builder.value(source());
|
||||||
} else {
|
|
||||||
builder.rawField("_source", source());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fields != null && !fields.isEmpty()) {
|
if (fields != null && !fields.isEmpty()) {
|
||||||
|
|
Loading…
Reference in New Issue