Java Code Examples for org.elasticsearch.action.search.SearchRequestBuilder#setSearchType()
The following examples show how to use
org.elasticsearch.action.search.SearchRequestBuilder#setSearchType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchTransportFactory.java From database-transform-tool with Apache License 2.0 | 7 votes |
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; }
Example 2
Source File: ElasticsearchExtendTransportFactory.java From database-transform-tool with Apache License 2.0 | 7 votes |
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; }
Example 3
Source File: ElasticsearchTransportFactory.java From database-transform-tool with Apache License 2.0 | 6 votes |
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; }
Example 4
Source File: EsAbstractConditionBean.java From fess with Apache License 2.0 | 5 votes |
public void build(SearchRequestBuilder builder) { if (explain != null) { builder.setExplain(explain); } if (minScore != null) { builder.setMinScore(minScore); } if (preference != null) { builder.setPreference(preference); } if (routing != null) { builder.setRouting(routing); } if (searchType != null) { builder.setSearchType(searchType); } if (timeoutInMillis != -1) { builder.setTimeout(new TimeValue(timeoutInMillis)); } if (version != null) { builder.setVersion(version); } if (seqNoAndPrimaryTerm != null) { builder.seqNoAndPrimaryTerm(seqNoAndPrimaryTerm); } if (terminateAfter > 0) { builder.setTerminateAfter(terminateAfter); } }
Example 5
Source File: EsAbstractConditionBean.java From fess with Apache License 2.0 | 5 votes |
public void build(SearchRequestBuilder builder) { if (explain != null) { builder.setExplain(explain); } if (minScore != null) { builder.setMinScore(minScore); } if (preference != null) { builder.setPreference(preference); } if (routing != null) { builder.setRouting(routing); } if (searchType != null) { builder.setSearchType(searchType); } if (timeoutInMillis != -1) { builder.setTimeout(new TimeValue(timeoutInMillis)); } if (version != null) { builder.setVersion(version); } if (seqNoAndPrimaryTerm != null) { builder.seqNoAndPrimaryTerm(seqNoAndPrimaryTerm); } if (terminateAfter > 0) { builder.setTerminateAfter(terminateAfter); } }
Example 6
Source File: EsAbstractConditionBean.java From fess with Apache License 2.0 | 5 votes |
public void build(SearchRequestBuilder builder) { if (explain != null) { builder.setExplain(explain); } if (minScore != null) { builder.setMinScore(minScore); } if (preference != null) { builder.setPreference(preference); } if (routing != null) { builder.setRouting(routing); } if (searchType != null) { builder.setSearchType(searchType); } if (timeoutInMillis != -1) { builder.setTimeout(new TimeValue(timeoutInMillis)); } if (version != null) { builder.setVersion(version); } if (seqNoAndPrimaryTerm != null) { builder.seqNoAndPrimaryTerm(seqNoAndPrimaryTerm); } if (terminateAfter > 0) { builder.setTerminateAfter(terminateAfter); } }
Example 7
Source File: EsQuery.java From AsuraFramework with Apache License 2.0 | 4 votes |
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; }