|
|
@@ -15,6 +15,11 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import javafx.util.Pair;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
|
|
|
+import org.elasticsearch.client.HeapBufferedAsyncResponseConsumer;
|
|
|
+import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
|
|
|
+import org.elasticsearch.client.RequestOptions;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
@@ -25,6 +30,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Modifier;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -108,7 +115,9 @@ public class ElasticSearchController {
|
|
|
page = page - 1;
|
|
|
String indexName = "docs_" + spaceId;
|
|
|
esConfig.setIndexName(indexName);
|
|
|
+
|
|
|
try {
|
|
|
+ setBuffer();
|
|
|
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Order.desc("id")));
|
|
|
long total = esService.countByContent(keyword);
|
|
|
List<SearchHit<EsDocInfo>> all = esService.findByContent(keyword, pageable);
|
|
|
@@ -133,4 +142,32 @@ public class ElasticSearchController {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置es查询buffer大小
|
|
|
+ */
|
|
|
+ private void setBuffer() {
|
|
|
+ try {
|
|
|
+ //设置es查询buffer大小
|
|
|
+ RequestOptions requestOptions = RequestOptions.DEFAULT;
|
|
|
+ Class<? extends RequestOptions> reqClass = requestOptions.getClass();
|
|
|
+ Field reqField = reqClass.getDeclaredField("httpAsyncResponseConsumerFactory");
|
|
|
+ reqField.setAccessible(true);
|
|
|
+ //去除final
|
|
|
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
|
|
|
+ modifiersField.setAccessible(true);
|
|
|
+ modifiersField.setInt(reqField, reqField.getModifiers() & ~Modifier.FINAL);
|
|
|
+ //设置默认的工厂
|
|
|
+ reqField.set(requestOptions, new HttpAsyncResponseConsumerFactory() {
|
|
|
+ @Override
|
|
|
+ public HttpAsyncResponseConsumer<HttpResponse> createHttpAsyncResponseConsumer() {
|
|
|
+ //1GB
|
|
|
+ return new HeapBufferedAsyncResponseConsumer(5 * 100 * 1024 * 1024);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (NoSuchIndexException | IllegalAccessException e) {
|
|
|
+ } catch (NoSuchFieldException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|