本文整理汇总了Java中org.elasticsearch.index.query.QueryStringQueryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java QueryStringQueryBuilder类的具体用法?Java QueryStringQueryBuilder怎么用?Java QueryStringQueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryStringQueryBuilder类属于org.elasticsearch.index.query包,在下文中一共展示了QueryStringQueryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: urlParamsToQueryBuilder
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
public static QueryBuilder urlParamsToQueryBuilder(RestRequest request) {
String queryString = request.param("q");
if (queryString == null) {
return null;
}
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
queryBuilder.defaultField(request.param("df"));
queryBuilder.analyzer(request.param("analyzer"));
queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
queryBuilder.lenient(request.paramAsBoolean("lenient", null));
String defaultOperator = request.param("default_operator");
if (defaultOperator != null) {
queryBuilder.defaultOperator(Operator.fromString(defaultOperator));
}
return queryBuilder;
}
示例2: getTopicByCateAndUser
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
@Override
public FacetedPage<Topic> getTopicByCateAndUser(String cate , String q , String user ,final int p , final int ps) {
FacetedPage<Topic> pages = null ;
NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(termQuery("cate" , cate)).withQuery(termQuery("creater" , user)).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC));
if(!StringUtils.isBlank(q)){
searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
}
SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps));
if(elasticsearchTemplate.indexExists(Topic.class)){
if(!StringUtils.isBlank(q)){
pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class, new UKResultMapper());
}else{
pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class);
}
}
return pages ;
}
示例3: elasticSearch
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
private static void elasticSearch(JestClient client, String indexName, String type, String query) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(query);
searchSourceBuilder.query(queryStringQueryBuilder);
Search searchElastic = (Search) new Search.Builder(searchSourceBuilder.toString())
// multiple index or types can be added.
.addIndex(indexName).addType(type).build();
try {
SearchResult elasticRs = client.execute(searchElastic);
List<Hit<Article, Void>> hits = elasticRs.getHits(Article.class);
for (Hit<Article, Void> hit : hits) {
Article talk = hit.source;
System.out.println("Elastic hits: " + talk.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: parseQuerySource
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
public static QuerySourceBuilder parseQuerySource(RestRequest request) {
String queryString = request.param("q");
if (queryString == null) {
return null;
}
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
queryBuilder.defaultField(request.param("df"));
queryBuilder.analyzer(request.param("analyzer"));
queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
queryBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true));
queryBuilder.lenient(request.paramAsBoolean("lenient", null));
String defaultOperator = request.param("default_operator");
if (defaultOperator != null) {
if ("OR".equals(defaultOperator)) {
queryBuilder.defaultOperator(QueryStringQueryBuilder.Operator.OR);
} else if ("AND".equals(defaultOperator)) {
queryBuilder.defaultOperator(QueryStringQueryBuilder.Operator.AND);
} else {
throw new IllegalArgumentException("Unsupported defaultOperator [" + defaultOperator + "], can either be [OR] or [AND]");
}
}
return new QuerySourceBuilder().setQuery(queryBuilder);
}
示例5: findByCon
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public FacetedPage<Serializable> findByCon(Class clazz,NativeSearchQueryBuilder searchQueryBuilder, String q , final int p , final int ps) {
FacetedPage<Serializable> pages = null ;
if(!StringUtils.isBlank(q)){
searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
}
SearchQuery searchQuery = searchQueryBuilder.build();
if(elasticsearchTemplate.indexExists(clazz)){
if(!StringUtils.isBlank(q)){
pages = elasticsearchTemplate.queryForPage(searchQuery, clazz, new UKResultMapper());
}else{
pages = elasticsearchTemplate.queryForPage(searchQuery, clazz , new UKAggTopResultExtractor("userid" , "top"));
}
}
return pages ;
}
示例6: findByCon
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
@Override
public FacetedPage<Topic> findByCon(NativeSearchQueryBuilder searchQueryBuilder, String q , final int p , final int ps) {
FacetedPage<Topic> pages = null ;
if(!StringUtils.isBlank(q)){
searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
}
SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps));
if(elasticsearchTemplate.indexExists(Topic.class)){
if(!StringUtils.isBlank(q)){
pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class , new UKResultMapper());
}else{
pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class);
}
}
return pages ;
}
示例7: doQueryString
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
/**
* query_string-分词搜索
*
* @param boolQ
* @param conditions
* @param conditionType
*/
private void doQueryString(BoolQueryBuilder boolQ, List<Condition> conditions,
ConditionType conditionType) {
// 构造查询语法串
StringBuilder build = new StringBuilder();
String filed;
List<String> words;
for (Condition condition : conditions) {
filed = condition.getFiled();
filed = StringUtils.isBlank(filed) ? "_all" : filed;
words = KeyWordUtil.processKeyWord(condition.getValue());
for (String word : words) {
build.append("(").append(filed).append(":").append(word).append(") ")
.append(conditionType.name());
}
}
if (build.length() < 1) {
return;
}
String querystring = build.substring(0, build.lastIndexOf(conditionType.name()));
QueryStringQueryBuilder queryString = QueryBuilders.queryString(querystring)
.defaultOperator(default_operator);
mergeBuilder(boolQ, queryString, conditionType);
}
示例8: search
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
@Override
public SearchResponse search(SearchRequest searchRequest) throws InvalidSearchException {
// Wrap the query to also get any meta-alerts.
QueryBuilder qb = constantScoreQuery(boolQuery()
.must(boolQuery()
.should(new QueryStringQueryBuilder(searchRequest.getQuery()))
.should(nestedQuery(
ALERT_FIELD,
new QueryStringQueryBuilder(searchRequest.getQuery()),
ScoreMode.None
)
)
)
// Ensures that it's a meta alert with active status or that it's an alert (signified by
// having no status field)
.must(boolQuery()
.should(termQuery(MetaAlertDao.STATUS_FIELD, MetaAlertStatus.ACTIVE.getStatusString()))
.should(boolQuery().mustNot(existsQuery(MetaAlertDao.STATUS_FIELD)))
)
.mustNot(existsQuery(MetaAlertDao.METAALERT_FIELD))
);
return elasticsearchDao.search(searchRequest, qb);
}
示例9: handleFulltextSearchSettings
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
/**
* @param querySettings
* @return builder for query, newer null
*/
protected QueryBuilder handleFulltextSearchSettings(QuerySettings querySettings) {
if (querySettings.getQuery() != null) {
QueryStringQueryBuilder qb = QueryBuilders.queryString(querySettings.getQuery());
Map<String, Object> fields = configService.get(ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS);
if (fields != null) {
for (String fieldName : fields.keySet()) {
String value = (String) fields.get(fieldName);
if (value != null && !value.trim().isEmpty()) {
try {
qb.field(fieldName, Float.parseFloat(value));
} catch (NumberFormatException e) {
log.warning("Boost value has not valid float format for fulltext field " + fieldName
+ " in DCP configuration document " + ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS);
qb.field(fieldName);
}
} else {
qb.field(fieldName);
}
}
}
return qb;
} else {
return QueryBuilders.matchAllQuery();
}
}
示例10: addQuery
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
private void addQuery(BoolQueryBuilder boolQuery, boolean positive, String query, String modifier) {
if (Strings.isNullOrEmpty(query)) {
return;
}
QueryStringQueryBuilder builder = QueryBuilders.queryStringQuery(query)
.field("title." + modifier)
.field("text." + modifier)
.defaultOperator(Operator.AND);
if (positive) {
boolQuery.must(builder);
} else {
boolQuery.mustNot(builder);
}
}
示例11: findByCon
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
@Override
public FacetedPage<TopicComment> findByCon(NativeSearchQueryBuilder searchQueryBuilder , String field , String aggname, String q , final int p , final int ps) {
FacetedPage<TopicComment> pages = null ;
if(!StringUtils.isBlank(q)){
searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
}
SearchQuery searchQuery = searchQueryBuilder.build();
if(elasticsearchTemplate.indexExists(TopicComment.class)){
if(!StringUtils.isBlank(q)){
pages = elasticsearchTemplate.queryForPage(searchQuery, TopicComment.class , new UKResultMapper());
}else{
pages = elasticsearchTemplate.queryForPage(searchQuery, TopicComment.class , new UKAggTopResultExtractor(field , aggname));
}
}
return pages ;
}
示例12: getTopicByCate
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
@Override
public FacetedPage<Topic> getTopicByCate(String cate , String q, final int p , final int ps) {
FacetedPage<Topic> pages = null ;
NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(termQuery("cate" , cate)).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC));
if(!StringUtils.isBlank(q)){
searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
}
searchQueryBuilder.withHighlightFields(new HighlightBuilder.Field("title").fragmentSize(200)) ;
SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps)) ;
if(elasticsearchTemplate.indexExists(Topic.class)){
if(!StringUtils.isBlank(q)){
pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class , new UKResultMapper());
}else{
pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class);
}
}
return pages ;
}
示例13: fullParamer
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
public static ToXContent fullParamer(QueryStringQueryBuilder query, Paramer paramer) {
if (paramer.analysis != null) {
query.analyzer(paramer.analysis);
}
if (paramer.boost != null) {
query.boost(paramer.boost);
}
return query;
}
示例14: queryBuilder
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
/**
* construct the only query used by all
*
* @param query
* @return
*/
private static QueryBuilder queryBuilder(String query) {
//return QueryBuilders.queryStringQuery(query).defaultOperator(QueryStringQueryBuilder.Operator.AND);
if (StringUtils.isEmpty(query)) {
return QueryBuilders.matchAllQuery();
}
// return QueryBuilders.multiMatchQuery(query)
// .operator(MatchQueryBuilder.Operator.AND)
// .field("name^3")
// .field("content").field("path").field("version").field("project")
// ;
return QueryBuilders.queryStringQuery(query)
.allowLeadingWildcard(true)
.defaultOperator(QueryStringQueryBuilder.Operator.AND)
.field("name^3")
.field("content").field("path").field("version").field("project").field("extension")
;
//QueryBuilders.queryStringQuery(query)
//.defaultOperator(QueryStringQueryBuilder.Operator.AND)
//TODO : attention, si on souhaite que la recherche s'effectue bien sur l'ensemble des champs
//il faut veuillez à ce qu'il soit tous présent ici
//en cas d'ajout, penser à les ajouter ici
//.field("content")
/* return QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery("content", query))
.should(
QueryBuilders.queryStringQuery(query)
.defaultOperator(QueryStringQueryBuilder.Operator.AND)
);*/
}
示例15: getTaskLogs
import org.elasticsearch.index.query.QueryStringQueryBuilder; //导入依赖的package包/类
@Override
public List<TaskExecLog> getTaskLogs(String taskId) {
try {
QueryBuilder qf = QueryBuilders.matchAllQuery();
Expression expression = Expression.fromString("taskId='" + taskId + "'");
qf = expression.getFilterBuilder();
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(qf);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
final SearchRequestBuilder srb = client.prepareSearch(indexName).setQuery(fq).setTypes(TASK_DOC_TYPE);
SearchResponse response = srb.execute().actionGet();
SearchHit[] hits = response.getHits().getHits();
List<TaskExecLog> logs = new ArrayList<>(hits.length);
for(SearchHit hit : hits) {
String source = hit.getSourceAsString();
TaskExecLog tel = om.readValue(source, TaskExecLog.class);
logs.add(tel);
}
return logs;
}catch(Exception e) {
log.error(e.getMessage(), e);
}
return null;
}