SearchSourceBuilder sourceBuilder=new SearchSourceBuilder ();
//query condition
//create BoolQueryBuilder object
BoolQueryBuilder BoolQueryBuilder=new BoolQueryBuilder ();
//under the matching index of all field participle query
QueryStringQueryBuilder criteriabuilder=QueryBuilders
QueryStringQuery (inputValue. GetValue ());
//configuration hanlp participles,
Criteriabuilder. Analyzer (" hanlp - index ");
Criteriabuilder. UseDisMax (true);
//child boolQueryBuilder condition condition, used to represent the query conditions or the relationship between the
BoolQueryBuilder childBoolQueryBuilder=new BoolQueryBuilder ()
Should (criteriabuilder);
//query condition is added to the boolQueryBuilder
BoolQueryBuilder. Must (childBoolQueryBuilder);
SourceBuilder. Query (boolQueryBuilder);
//how much each page article data
SourceBuilder. Size (10000);
//add highlighting
//sourceBuilder. Highlighter (highlightBuilder);
//add the request body into the request
The searchRequest. Source (sourceBuilder);
//set the timeout
The searchRequest. Scroll (TimeValue timeValueMinutes (1 l));
//3, send the request
The SearchResponse the SearchResponse;
The searchResponse=esc. Client. The search (searchRequest);
//System. Out. Println (the searchResponse. ToString ());
//processing search accuracy document the results
SearchHits hits.=the searchResponse getHits ();
//retrieve the number of hit
Long totalHits=hits. GetTotalHits ();
Float maxScore=hits. GetMaxScore ();
//get scrollID
String scrollId=the searchResponse. GetScrollId ();
System. Out.println (" scrollId - & gt;" + scrollId);
SearchHit [] searchHits=hits. GetHits ();
//get data matching, total
For (SearchHit hit: searchHits) {
//take _source field values
String sourceAsString=hit. GetSourceAsString ();//take into a json string
//sourList. Add (sourceAsString);
//sourList. Add (scrollId);
}
I have been here for the total number of data in a match, every time I want to take 20 article, click the next page, article 20 after the query out
CodePudding user response:
Every time take 20 hit, my idea is to take hitString cycle, on the list, and then returnPseudo code:
Int limit=0;
For (SearchHit hit: hits. GetHits ()) {
If (limit==page) {
break;
}
String hitString=hit. GetSourceAsString ();
List. The add (hitString);
//here take index 1-20
Limit++;
}
CodePudding user response:
The building Lord, how to write ah, now have the answer? I also met this problem