import com.google.common.base.Preconditions;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
++import org.elasticsearch.action.search.SearchScrollRequestBuilder;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
*/
@Deprecated
public List<Rule> getByIds(Collection<Integer> ids) {
- SearchResponse scrollResp = getClient().prepareSearch(this.getIndexName())
+ SearchRequestBuilder request = getClient().prepareSearch(this.getIndexName())
.setTypes(this.getIndexType())
- .setQuery(QueryBuilders.termsQuery(RuleNormalizer.RuleField.ID.field(), ids))
- .get();
+ .setSearchType(SearchType.SCAN)
+ .setScroll(TimeValue.timeValueSeconds(3L))
+ .setSize(100)
- SearchResponse response = node.execute(request);
+ .setQuery(QueryBuilders.termsQuery(RuleNormalizer.RuleField.ID.field(), ids));
++ SearchResponse scrollResp = node.execute(request);
List<Rule> rules = newArrayList();
- for (SearchHit hit : response.getHits()) {
- rules.add(toDoc(hit.getSource()));
+ while (true) {
- scrollResp = getClient()
++ SearchScrollRequestBuilder scrollRequest = getClient()
+ .prepareSearchScroll(scrollResp.getScrollId())
- .setScroll(TimeValue.timeValueSeconds(3L))
- .get();
++ .setScroll(TimeValue.timeValueSeconds(3L));
++
++ scrollResp = node.execute(scrollRequest);
++
+ for (SearchHit hit : scrollResp.getHits()) {
+ rules.add(toDoc(hit.getSource()));
+ }
+ //Break condition: No hits are returned
+ if (scrollResp.getHits().getHits().length == 0) {
+ break;
+ }
}
return rules;
}