直接使用 postman 调用 用时一秒
http://106.13.148.210:9200/_search
{
"query": {
"match": {
"book_id": {
"query": 87,
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
},
"size": 500
}
使用 java 代码 8 秒多
/* SearchRequest searchRequest = new SearchRequest("web_book_chapter");
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("book_id", 48);
// matchQueryBuilder.
sourceBuilder.query(matchQueryBuilder);
sourceBuilder.size(200);
System.out.println(sourceBuilder.toString());
sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
searchRequest.source(sourceBuilder);
long startTime=System.currentTimeMillis();
try {
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
long endTime=System.currentTimeMillis();
System.out.println("程序运行时间: "+(endTime - startTime)+"ms");
SearchHits hits = searchResponse.getHits();
SearchHit[] searchHits = hits.getHits();
for (SearchHit hit : searchHits) {
String sourceAsString = hit.getSourceAsString();
BookChapterModel bookChapterModel = JSON.parseObject(sourceAsString, BookChapterModel.class);
list.add(bookChapterModel);
}
}catch (Exception e){
e.printStackTrace();
}
@Bean
public RestHighLevelClient restHighLevelClient(){
long startTime=System.currentTimeMillis();
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(
RestClient.builder(
new HttpHost("106.13.148.210", 9200,"http")
)
);
long endTime=System.currentTimeMillis();
System.out.println("初始化客户端时间: "+(endTime - startTime)+"ms");
return restHighLevelClient;
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.