直接使用 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;
}