reindex from remote to read content-type header rather than guessing content type based on content
This commit is contained in:
parent
54fa997545
commit
bce54cf38d
|
@ -34,9 +34,8 @@ import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||||
import org.elasticsearch.common.xcontent.XContent;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.index.reindex.ScrollableHitSource;
|
import org.elasticsearch.index.reindex.ScrollableHitSource;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
|
@ -141,8 +140,9 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
|
||||||
T parsedResponse;
|
T parsedResponse;
|
||||||
try {
|
try {
|
||||||
InputStream content = response.getEntity().getContent();
|
InputStream content = response.getEntity().getContent();
|
||||||
XContent xContent = XContentFactory.xContentType(content).xContent();
|
XContentType xContentType = XContentType.fromMediaTypeOrFormat(
|
||||||
try(XContentParser xContentParser = xContent.createParser(content)) {
|
response.getEntity().getContentType().getValue());
|
||||||
|
try(XContentParser xContentParser = xContentType.xContent().createParser(content)) {
|
||||||
parsedResponse = parser.apply(xContentParser, () -> ParseFieldMatcher.STRICT);
|
parsedResponse = parser.apply(xContentParser, () -> ParseFieldMatcher.STRICT);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.ProtocolVersion;
|
import org.apache.http.ProtocolVersion;
|
||||||
import org.apache.http.StatusLine;
|
import org.apache.http.StatusLine;
|
||||||
import org.apache.http.concurrent.FutureCallback;
|
import org.apache.http.concurrent.FutureCallback;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
import org.apache.http.entity.InputStreamEntity;
|
import org.apache.http.entity.InputStreamEntity;
|
||||||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
||||||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
||||||
|
@ -360,7 +361,7 @@ public class RemoteScrollableHitSourceTests extends ESTestCase {
|
||||||
} else {
|
} else {
|
||||||
StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "");
|
StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "");
|
||||||
HttpResponse httpResponse = new BasicHttpResponse(statusLine);
|
HttpResponse httpResponse = new BasicHttpResponse(statusLine);
|
||||||
httpResponse.setEntity(new InputStreamEntity(resource.openStream()));
|
httpResponse.setEntity(new InputStreamEntity(resource.openStream(), ContentType.APPLICATION_JSON));
|
||||||
futureCallback.completed(httpResponse);
|
futureCallback.completed(httpResponse);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue