本文整理匯總了Java中org.elasticsearch.action.search.SearchRequestBuilder.setTypes方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchRequestBuilder.setTypes方法的具體用法?Java SearchRequestBuilder.setTypes怎麽用?Java SearchRequestBuilder.setTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.action.search.SearchRequestBuilder
的用法示例。
在下文中一共展示了SearchRequestBuilder.setTypes方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deleteAllTest
import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
@Test
public void deleteAllTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
delete(String.format("DELETE FROM %s/account_temp", TEST_INDEX));
// Assert no results exist for this type.
SearchRequestBuilder request = MainTestSuite.getClient().prepareSearch(TEST_INDEX);
request.setTypes("account_temp");
SearchResponse response = request.setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(response.getHits().getTotalHits(), equalTo(0L));
}
示例2: deleteWithConditionTest
import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
@Test
public void deleteWithConditionTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
delete(String.format("DELETE FROM %s/phrase WHERE phrase = 'quick fox here' ", TEST_INDEX));
// Assert no results exist for this type.
SearchRequestBuilder request = MainTestSuite.getClient().prepareSearch(TEST_INDEX);
request.setTypes("phrase");
SearchResponse response = request.setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(response.getHits().getTotalHits(), equalTo(3L));
}
示例3: buildSearchRequest
import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
private SearchRequestBuilder buildSearchRequest (EsQueryDo esQueryObj) throws EsException {
if (Check.NuNStrStrict(esClientFactory.getIndexs(esQueryObj.getIndexName()))) {
throw new EsException("沒有指定要搜索的索引名稱(indexName)");
}
for (ThreadPoolStats.Stats stats : esClientFactory.getClient().threadPool().stats()) {
logger.info(JSON.toJSONString(stats));
}
//加載要搜索索引
SearchRequestBuilder searchRequestBuilder = esClientFactory.getClient().prepareSearch(esClientFactory.getIndexs(esQueryObj.getIndexName()));
//由spring從配置加載要搜索的index的類型
searchRequestBuilder.setTypes(esQueryObj.getTypeName());
//由spring從配置加載要搜索的類型
searchRequestBuilder.setSearchType(SearchType.fromId(esQueryObj.getSearchType()));
//查詢可以為null
searchRequestBuilder.setQuery(esQueryObj.getQueryBuilder());
if (!Check.NuNCollection(esQueryObj.getSortBuilders())) {
for (SortBuilder sortBuilder : esQueryObj.getSortBuilders()) {
searchRequestBuilder.addSort(sortBuilder);
}
}
if (!Check.NuNCollection(esQueryObj.getAggregationBuilders())) {
for (AbstractAggregationBuilder aggregationBuilder : esQueryObj.getAggregationBuilders()) {
searchRequestBuilder.addAggregation(aggregationBuilder);
}
}
//設置高亮域
if (esQueryObj.isHighLigth()) {
if (!Check.NuNObject(esQueryObj.highLigthFields())) {
for (String hlFieldName : esQueryObj.highLigthFields()) {
searchRequestBuilder.addHighlightedField(hlFieldName).setHighlighterPreTags(esQueryObj.getHighLigthPreTag())
.setHighlighterPostTags(esQueryObj.getHighLigthPostTag());
}
}
}
//分頁
searchRequestBuilder.setFrom(esQueryObj.getFromIndex()).setSize(esQueryObj.getSize());
searchRequestBuilder.setExplain(esQueryObj.isExplain());
return searchRequestBuilder;
}