本文整理汇总了Java中org.elasticsearch.action.search.SearchRequestBuilder.setExplain方法的典型用法代码示例。如果您正苦于以下问题:Java SearchRequestBuilder.setExplain方法的具体用法?Java SearchRequestBuilder.setExplain怎么用?Java SearchRequestBuilder.setExplain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.search.SearchRequestBuilder
的用法示例。
在下文中一共展示了SearchRequestBuilder.setExplain方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: queryForObject
import org.elasticsearch.action.search.SearchRequestBuilder; //导入方法依赖的package包/类
/**
* 查询返回一个Map对象
*
* @param esIndexName
* @param type
* @param fields
* @param content
* @param sortField
* @param order
* @param from
* @param size
* @return
*/
public List<Map<String, Object>> queryForObject(String esIndexName, String type, String[] fields, String content, String sortField, SortOrder order, List<String> heightFields, int from, int size) {
SearchRequestBuilder reqBuilder = esClient.prepareSearch(esIndexName)
.setTypes(type).setSearchType(SearchType.DEFAULT)
.setExplain(true);
QueryStringQueryBuilder queryString = QueryBuilders.queryStringQuery("\"" + content + "\"");
for (String k : fields) {
queryString.field(k);
}
queryString.minimumShouldMatch("10");
reqBuilder.setExplain(true);
reqBuilder.setQuery(QueryBuilders.boolQuery().should(queryString))
.setExplain(true);
if (StringUtils.isNotEmpty(sortField) && order != null) {
reqBuilder.addSort(sortField, order);
}
if (from >= 0 && size > 0) {
reqBuilder.setFrom(from).setSize(size);
}
//设置高亮显示
if (heightFields != null) {
for (String hs : heightFields)
reqBuilder.addHighlightedField(hs);
}
reqBuilder.setHighlighterPreTags("<span style=\"color:red\">");
reqBuilder.setHighlighterPostTags("</span>");
SearchResponse resp = reqBuilder.execute().actionGet();
SearchHit[] hits = resp.getHits().getHits();
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
for (SearchHit hit : hits) {
Map<String, Object> map = new HashMap<String, Object>();
for (String key : hit.getSource().keySet()) {
if (heightFields != null && heightFields.contains(key)) {
map.put(key, hit.getHighlightFields().get(key).fragments()[0]);
} else
map.put(key, hit.getSource().get(key));
}
results.add(map);
}
return results;
}