當前位置: 首頁>>代碼示例>>Java>>正文


Java SearchRequestBuilder.setSearchType方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.search.SearchRequestBuilder.setSearchType方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchRequestBuilder.setSearchType方法的具體用法?Java SearchRequestBuilder.setSearchType怎麽用?Java SearchRequestBuilder.setSearchType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.search.SearchRequestBuilder的用法示例。


在下文中一共展示了SearchRequestBuilder.setSearchType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testScore

import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
public void testScore() throws Exception {
    createIndex("test");
    ensureGreen("test");
    indexRandom(true,
            client().prepareIndex("test", "doc", "1").setSource("text", "hello goodbye"),
            client().prepareIndex("test", "doc", "2").setSource("text", "hello hello hello goodbye"),
            client().prepareIndex("test", "doc", "3").setSource("text", "hello hello goodebye"));
    ScoreFunctionBuilder<?> score = ScoreFunctionBuilders.scriptFunction(new Script(ScriptType.INLINE, "expression", "1 / _score", Collections.emptyMap()));
    SearchRequestBuilder req = client().prepareSearch().setIndices("test");
    req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode(CombineFunction.REPLACE));
    req.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); // make sure DF is consistent
    SearchResponse rsp = req.get();
    assertSearchResponse(rsp);
    SearchHits hits = rsp.getHits();
    assertEquals(3, hits.getTotalHits());
    assertEquals("1", hits.getAt(0).getId());
    assertEquals("3", hits.getAt(1).getId());
    assertEquals("2", hits.getAt(2).getId());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:MoreExpressionTests.java

示例2: selectAll

import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
public String selectAll(String indexs,String types,String condition){
	try {
		if(client==null){
			init();
		}
		SearchRequestBuilder request = client.prepareSearch(indexs.split(",")).setTypes(types.split(","));
		request.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
		request.setQuery(QueryBuilders.queryStringQuery(condition));
		request.setExplain(false);
		SearchResponse response = request.get();
		return response.toString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:18,代碼來源:ElasticsearchTransportFactory.java

示例3: selectMatchAll

import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
public String selectMatchAll(String indexs,String types,String field,String value){
	try {
		if(client==null){
			init();
		}
		SearchRequestBuilder request = client.prepareSearch(indexs.split(",")).setTypes(types.split(","));
		request.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
		request.setQuery(QueryBuilders.matchQuery(field, value));
		request.highlighter(new HighlightBuilder().field(field));
		request.addAggregation(AggregationBuilders.terms("data").field(field+".keyword"));
		request.setExplain(false);
		SearchResponse response = request.get();
		return response.toString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:20,代碼來源:ElasticsearchTransportFactory.java

示例4: selectTermAll

import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
public String selectTermAll(String indexs,String types,String field,String value){
	try {
		if(client==null){
			init();
		}
		SearchRequestBuilder request = client.prepareSearch(indexs.split(",")).setTypes(types.split(","));
		request.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
		request.setQuery(QueryBuilders.termQuery(field, value));
		request.highlighter(new HighlightBuilder().field(field));
		request.addAggregation(AggregationBuilders.terms("data").field(field+".keyword"));
		request.setExplain(false);
		SearchResponse response = request.get();
		return response.toString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:20,代碼來源:ElasticsearchExtendTransportFactory.java

示例5: 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;
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:42,代碼來源:EsQuery.java


注:本文中的org.elasticsearch.action.search.SearchRequestBuilder.setSearchType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。