org.elasticsearch.index.query.QueryStringQueryBuilder Java Examples
The following examples show how to use
org.elasticsearch.index.query.QueryStringQueryBuilder.
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: RestActions.java From Elasticsearch with Apache License 2.0 | 8 votes |
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); }
Example #2
Source File: QuickReplyRepositoryImpl.java From youkefu with Apache License 2.0 | 7 votes |
@Override public List<QuickReply> getQuickReplyByOrgi(String orgi , String cate,String type, String q) { List<QuickReply> list = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(termQuery("orgi" , orgi)) ; if(!StringUtils.isBlank(cate)){ boolQueryBuilder.must(termQuery("cate" , cate)) ; } if(!StringUtils.isBlank(type)){ boolQueryBuilder.must(termQuery("type" , type)) ; } if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC)); SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(0, 10000)); if(elasticsearchTemplate.indexExists(QuickReply.class)){ list = elasticsearchTemplate.queryForList(searchQuery, QuickReply.class); } return list ; }
Example #3
Source File: ElasticSearchRestDAOV5.java From conductor with Apache License 2.0 | 6 votes |
private SearchResult<String> searchObjectIdsViaExpression(String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) { try { // Build query QueryBuilder queryBuilder = QueryBuilders.matchAllQuery(); if(StringUtils.isNotEmpty(structuredQuery)) { Expression expression = Expression.fromString(structuredQuery); queryBuilder = expression.getFilterBuilder(); } BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder); QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery(freeTextQuery); BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery); return searchObjectIds(indexName, fq, start, size, sortOptions, docType); } catch (Exception e) { throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e); } }
Example #4
Source File: KbsTopicRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<KbsTopic> getTopicByCate(String cate , String q, final int p , final int ps) { Page<KbsTopic> pages = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(termQuery("cate" , cate)) ; if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withSort(new FieldSortBuilder("createtime").unmappedType("date").order(SortOrder.DESC)); searchQueryBuilder.withHighlightFields(new HighlightBuilder.Field("title").fragmentSize(200)) ; SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps)) ; if(elasticsearchTemplate.indexExists(KbsTopic.class)){ pages = elasticsearchTemplate.queryForPage(searchQuery, KbsTopic.class , new UKResultMapper()); } return pages ; }
Example #5
Source File: KbsTopicRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public List<KbsTopic> getTopicByOrgi(String orgi , String type, String q) { List<KbsTopic> list = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(termQuery("orgi" , orgi)) ; if(!StringUtils.isBlank(type)){ boolQueryBuilder.must(termQuery("cate" , type)) ; } if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC)); SearchQuery searchQuery = searchQueryBuilder.build(); if(elasticsearchTemplate.indexExists(KbsTopic.class)){ list = elasticsearchTemplate.queryForList(searchQuery, KbsTopic.class); } return list ; }
Example #6
Source File: TopicRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<Topic> getTopicByCateAndOrgi(String cate ,String orgi, String q, final int p , final int ps) { Page<Topic> pages = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); if(!StringUtils.isBlank(cate)) { boolQueryBuilder.must(termQuery("cate" , cate)) ; } boolQueryBuilder.must(termQuery("orgi" , orgi)) ; if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("createtime").unmappedType("date").order(SortOrder.DESC)); searchQueryBuilder.withHighlightFields(new HighlightBuilder.Field("title").fragmentSize(200)) ; SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps)) ; if(elasticsearchTemplate.indexExists(Topic.class)){ pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class , new XiaoEUKResultMapper()); } return pages ; }
Example #7
Source File: TopicRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<Topic> getTopicByCateAndUser(String cate , String q , String user ,final int p , final int ps) { Page<Topic> pages = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(termQuery("cate" , cate)) ; if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withQuery(termQuery("creater" , user)).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC)); SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps)); if(elasticsearchTemplate.indexExists(Topic.class)){ pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class, new XiaoEUKResultMapper()); } return pages ; }
Example #8
Source File: QuickReplyRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<QuickReply> getByOrgiAndType(String orgi ,String type, String q , Pageable page) { Page<QuickReply> list = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(termQuery("orgi" , orgi)) ; if(!StringUtils.isBlank(type)) { boolQueryBuilder.must(termQuery("type" , type)) ; } if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withSort(new FieldSortBuilder("createtime").unmappedType("date").order(SortOrder.DESC)); SearchQuery searchQuery = searchQueryBuilder.build().setPageable(page); if(elasticsearchTemplate.indexExists(QuickReply.class)){ list = elasticsearchTemplate.queryForPage(searchQuery, QuickReply.class); } return list ; }
Example #9
Source File: TopicRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public List<Topic> getTopicByOrgi(String orgi , String type, String q) { List<Topic> list = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(termQuery("orgi" , orgi)) ; if(!StringUtils.isBlank(type)){ boolQueryBuilder.must(termQuery("cate" , type)) ; } if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC)); SearchQuery searchQuery = searchQueryBuilder.build(); if(elasticsearchTemplate.indexExists(Topic.class)){ list = elasticsearchTemplate.queryForList(searchQuery, Topic.class); } return list ; }
Example #10
Source File: KbsTopicCommentRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<KbsTopicComment> findByCon(NativeSearchQueryBuilder searchQueryBuilder , String field , String aggname, String q , final int p , final int ps) { Page<KbsTopicComment> pages = null ; if(!StringUtils.isBlank(q)){ searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } SearchQuery searchQuery = searchQueryBuilder.build(); if(elasticsearchTemplate.indexExists(KbsTopicComment.class)){ if(!StringUtils.isBlank(q)){ pages = elasticsearchTemplate.queryForPage(searchQuery, KbsTopicComment.class , new UKResultMapper()); }else{ pages = elasticsearchTemplate.queryForPage(searchQuery, KbsTopicComment.class , new UKAggTopResultExtractor(field , aggname)); } } return pages ; }
Example #11
Source File: ElasticsearchQueryBuilder.java From presto with Apache License 2.0 | 6 votes |
public static QueryBuilder buildSearchQuery(ConnectorSession session, TupleDomain<ElasticsearchColumnHandle> constraint, Optional<String> query) { BoolQueryBuilder queryBuilder = new BoolQueryBuilder(); if (constraint.getDomains().isPresent()) { for (Map.Entry<ElasticsearchColumnHandle, Domain> entry : constraint.getDomains().get().entrySet()) { ElasticsearchColumnHandle column = entry.getKey(); Domain domain = entry.getValue(); checkArgument(!domain.isNone(), "Unexpected NONE domain for %s", column.getName()); if (!domain.isAll()) { queryBuilder.filter(new BoolQueryBuilder().must(buildPredicate(session, column.getName(), domain, column.getType()))); } } } query.map(QueryStringQueryBuilder::new) .ifPresent(queryBuilder::must); if (queryBuilder.hasClauses()) { return queryBuilder; } return new MatchAllQueryBuilder(); }
Example #12
Source File: QuickReplyRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<QuickReply> getByOrgiAndCate(String orgi ,String cate , String q, Pageable page) { Page<QuickReply> pages = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(termQuery("cate" , cate)) ; if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withSort(new FieldSortBuilder("createtime").unmappedType("date").order(SortOrder.DESC)); searchQueryBuilder.withHighlightFields(new HighlightBuilder.Field("title").fragmentSize(200)) ; SearchQuery searchQuery = searchQueryBuilder.build().setPageable(page) ; if(elasticsearchTemplate.indexExists(QuickReply.class)){ pages = elasticsearchTemplate.queryForPage(searchQuery, QuickReply.class , new UKResultMapper()); } return pages ; }
Example #13
Source File: KbsTopicRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<KbsTopic> getTopicByCateAndUser(String cate , String q , String user ,final int p , final int ps) { Page<KbsTopic> pages = null ; BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(termQuery("cate" , cate)) ; if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withQuery(termQuery("creater" , user)).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC)); SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps)); if(elasticsearchTemplate.indexExists(KbsTopic.class)){ pages = elasticsearchTemplate.queryForPage(searchQuery, KbsTopic.class, new UKResultMapper()); } return pages ; }
Example #14
Source File: ContactsRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<Contacts> findByCreaterAndSharesAndOrgi(String creater, String shares ,String orgi, boolean includeDeleteData ,String q , Pageable page) { BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder1 = new BoolQueryBuilder(); boolQueryBuilder1.should(termQuery("creater" , creater)) ; boolQueryBuilder1.should(termQuery("shares" , creater)) ; boolQueryBuilder1.should(termQuery("shares" , "all")) ; boolQueryBuilder.must(boolQueryBuilder1) ; boolQueryBuilder.must(termQuery("orgi" ,orgi)) ; if(includeDeleteData){ boolQueryBuilder.must(termQuery("datastatus" , true)) ; }else{ boolQueryBuilder.must(termQuery("datastatus" , false)) ; } if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } return processQuery(boolQueryBuilder , page); }
Example #15
Source File: DecompoundQueryTests.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 6 votes |
public void testNestedCommonPhraseQuery() throws Exception { List<IndexRequestBuilder> reqs = new ArrayList<>(); reqs.add(client().prepareIndex("test", "_doc", "1").setSource("text", "deutsche Spielbankgesellschaft")); indexRandom(true, false, reqs); QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery("text:\"deutsche spielbankgesellschaft\""); ExactPhraseQueryBuilder exactPhraseQueryBuilder = new ExactPhraseQueryBuilder(queryStringQueryBuilder); SearchResponse resp = client().prepareSearch("test").setQuery(exactPhraseQueryBuilder).get(); ElasticsearchAssertions.assertHitCount(resp, 1L); assertHits(resp.getHits(), "1"); QueryStringQueryBuilder queryStringQueryBuilder2 = QueryBuilders.queryStringQuery("text:\"deutsche bank\""); ExactPhraseQueryBuilder exactPhraseQueryBuilder2 = new ExactPhraseQueryBuilder(queryStringQueryBuilder2); SearchResponse resp2 = client().prepareSearch("test").setQuery(exactPhraseQueryBuilder2).get(); ElasticsearchAssertions.assertHitCount(resp2, 0L); QueryStringQueryBuilder queryStringQueryBuilder3 = QueryBuilders.queryStringQuery("text:\"deutsche spielbankgesellschaft\" AND NOT text:\"deutsche bank\""); ExactPhraseQueryBuilder exactPhraseQueryBuilder3 = new ExactPhraseQueryBuilder(queryStringQueryBuilder3); SearchResponse resp3 = client().prepareSearch("test").setQuery(exactPhraseQueryBuilder3).get(); ElasticsearchAssertions.assertHitCount(resp3, 1L); assertHits(resp3.getHits(), "1"); }
Example #16
Source File: EntCustomerRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<EntCustomer> findByCreaterAndSharesAndOrgi(String creater, String shares ,String orgi, boolean includeDeleteData ,String q , Pageable page) { BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder1 = new BoolQueryBuilder(); boolQueryBuilder1.should(termQuery("creater" , creater)) ; boolQueryBuilder1.should(termQuery("shares" , creater)) ; boolQueryBuilder1.should(termQuery("shares" , "all")) ; boolQueryBuilder.must(boolQueryBuilder1) ; boolQueryBuilder.must(termQuery("orgi" , orgi)) ; if(includeDeleteData){ boolQueryBuilder.must(termQuery("datastatus" , true)) ; }else{ boolQueryBuilder.must(termQuery("datastatus" , false)) ; } if(!StringUtils.isBlank(q)){ boolQueryBuilder.must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ; } return processQuery(boolQueryBuilder , page); }
Example #17
Source File: ElasticsearchMetaAlertSearchDao.java From metron with Apache License 2.0 | 6 votes |
@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( MetaAlertConstants.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(MetaAlertConstants.STATUS_FIELD, MetaAlertStatus.ACTIVE.getStatusString())) .should(boolQuery().mustNot(existsQuery(MetaAlertConstants.STATUS_FIELD))) ) .mustNot(existsQuery(MetaAlertConstants.METAALERT_FIELD)) ); return elasticsearchDao.search(searchRequest, qb); }
Example #18
Source File: SearchTools.java From youkefu with Apache License 2.0 | 6 votes |
/** * * @param orgi * @param agent * @param p * @param ps * @return */ public static PageImpl<UKDataBean> namesearch(String orgi , String phonenum){ BoolQueryBuilder queryBuilder = new BoolQueryBuilder(); queryBuilder.must(termQuery("orgi", orgi)) ; queryBuilder.must(termQuery("validresult", "valid")) ; queryBuilder.must(termQuery("status", UKDataContext.NamesDisStatusType.DISAGENT.toString())) ; StringBuffer strb = new StringBuffer(); if(!StringUtils.isBlank(phonenum)) { strb.append(phonenum) ; if(phonenum.startsWith("0")) { strb.append(" ").append(phonenum.substring(1)) ; } }else { strb.append(UKDataContext.UKEFU_SYSTEM_NO_DAT) ; } queryBuilder.must(new QueryStringQueryBuilder(strb.toString()).defaultOperator(Operator.OR) ); return search(queryBuilder,0, 1); }
Example #19
Source File: EsQueryBuilder.java From es-service-parent with Apache License 2.0 | 6 votes |
/** * 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); }
Example #20
Source File: ElasticPolicyViewRepository.java From micronaut-microservices-poc with Apache License 2.0 | 6 votes |
@Override public Maybe<List<PolicyView>> findAll(FindPolicyQuery query) { SearchRequest searchRequest = new SearchRequest(INDEX_NAME); QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(query.getQueryText()) .field("number") .field("policyHolder"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(queryStringQueryBuilder).size(100); searchRequest.source(searchSourceBuilder); return elasticClientAdapter .search(searchRequest) .map(this::mapSearchResponse); }
Example #21
Source File: TestElasticSearchRestDAOV5.java From conductor with Apache License 2.0 | 6 votes |
private SearchResponse searchObjectIdsViaExpression(String indexName, String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) throws ParserException, IOException { // Build query QueryBuilder queryBuilder = QueryBuilders.matchAllQuery(); if(StringUtils.isNotEmpty(structuredQuery)) { Expression expression = Expression.fromString(structuredQuery); queryBuilder = expression.getFilterBuilder(); } BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder); QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery(freeTextQuery); BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery); return searchObjectIds(indexName, fq, start, size, sortOptions, docType); }
Example #22
Source File: TestElasticSearchDAOV5.java From conductor with Apache License 2.0 | 6 votes |
private SearchResponse search(String indexName, String structuredQuery, int start, int size, String freeTextQuery, String docType) throws ParserException { QueryBuilder queryBuilder = QueryBuilders.matchAllQuery(); if (StringUtils.isNotEmpty(structuredQuery)) { Expression expression = Expression.fromString(structuredQuery); queryBuilder = expression.getFilterBuilder(); } BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder); QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery(freeTextQuery); BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery); final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(indexName) .setQuery(fq) .setTypes(docType) .storedFields("_id") .setFrom(start) .setSize(size); return srb.get(); }
Example #23
Source File: ElasticSearchDAOV5.java From conductor with Apache License 2.0 | 6 votes |
@Override public List<Message> getMessages(String queue) { try { Expression expression = Expression.fromString("queue='" + queue + "'"); QueryBuilder queryBuilder = expression.getFilterBuilder(); BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder); QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*"); BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery); final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(logIndexPrefix + "*") .setQuery(fq) .setTypes(MSG_DOC_TYPE) .addSort(SortBuilders.fieldSort("created").order(SortOrder.ASC)); return mapGetMessagesResponse(srb.execute().actionGet()); } catch (Exception e) { String errorMsg = String.format("Failed to get messages for queue: %s", queue); logger.error(errorMsg, e); throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e); } }
Example #24
Source File: ElasticSearchDAOV5.java From conductor with Apache License 2.0 | 6 votes |
@Override public List<EventExecution> getEventExecutions(String event) { try { Expression expression = Expression.fromString("event='" + event + "'"); QueryBuilder queryBuilder = expression.getFilterBuilder(); BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder); QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*"); BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery); final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(logIndexPrefix + "*") .setQuery(fq).setTypes(EVENT_DOC_TYPE) .addSort(SortBuilders.fieldSort("created") .order(SortOrder.ASC)); return mapEventExecutionsResponse(srb.execute().actionGet()); } catch (Exception e) { String errorMsg = String.format("Failed to get executions for event: %s", event); logger.error(errorMsg, e); throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e); } }
Example #25
Source File: EkmKnowledgeMasterRepositoryImpl.java From youkefu with Apache License 2.0 | 6 votes |
@Override public Page<EkmKnowledgeMaster> findBySearchKnowledge(boolean datastatus, String q,String knowbaseid, String knowledgetype, String orgi, Pageable pageable) { BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder1 = new BoolQueryBuilder(); if(!StringUtils.isBlank(q)){ q = q.replaceAll("(OR|AND|NOT|:|\\(|\\))", "") ; boolQueryBuilder1.must(QueryBuilders.boolQuery().must(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND))) ; } if (!StringUtils.isBlank(knowledgetype)) { boolQueryBuilder.must(termQuery("knowledgetype" , knowledgetype)) ; } if (!StringUtils.isBlank(knowbaseid)) { boolQueryBuilder.must(termQuery("knowbaseid" , knowbaseid)) ; } boolQueryBuilder.must(termQuery("datastatus" , datastatus)) ; boolQueryBuilder.must(termQuery("orgi" ,orgi)) ; boolQueryBuilder.must(boolQueryBuilder1) ; //boolQueryBuilder.must(termQuery("pubstatus" , UKDataContext.PubStatusEnum.PASS.toString())) ;//审核通过 return processQuery(boolQueryBuilder , pageable); }
Example #26
Source File: EsAbstractConditionQuery.java From fess with Apache License 2.0 | 5 votes |
protected void doQueryString(String queryString, ConditionOptionCall<QueryStringQueryBuilder> opLambda) { QueryStringQueryBuilder queryStringQuery = QueryBuilders.queryStringQuery(queryString); regQ(queryStringQuery); if (opLambda != null) { opLambda.callback(queryStringQuery); } }
Example #27
Source File: ElasticsearchIndex.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private QueryStringQueryBuilder prepareQuery(IRI propertyURI, QueryStringQueryBuilder query) { // check out which query parser to use, based on the given property URI if (propertyURI == null) // if we have no property given, we create a default query parser which // has the TEXT_FIELD_NAME as the default field { query.defaultField(SearchFields.TEXT_FIELD_NAME).analyzer(queryAnalyzer); } else // otherwise we create a query parser that has the given property as // the default field { query.defaultField(toPropertyFieldName(SearchFields.getPropertyField(propertyURI))).analyzer(queryAnalyzer); } return query; }
Example #28
Source File: ElasticSearchBaseDAO.java From conductor with Apache License 2.0 | 5 votes |
BoolQueryBuilder boolQueryBuilder(String expression, String queryString) throws ParserException { QueryBuilder queryBuilder = QueryBuilders.matchAllQuery(); if (StringUtils.isNotEmpty(expression)) { Expression exp = Expression.fromString(expression); queryBuilder = exp.getFilterBuilder(); } BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder); QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery(queryString); return QueryBuilders.boolQuery().must(stringQuery).must(filterQuery); }
Example #29
Source File: ElasticSearchRestDAOV5.java From conductor with Apache License 2.0 | 5 votes |
@Override public List<EventExecution> getEventExecutions(String event) { try { Expression expression = Expression.fromString("event='" + event + "'"); QueryBuilder queryBuilder = expression.getFilterBuilder(); BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder); QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*"); BoolQueryBuilder query = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery); // Create the searchObjectIdsViaExpression source SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(query); searchSourceBuilder.sort(new FieldSortBuilder("created").order(SortOrder.ASC)); // Generate the actual request to send to ES. SearchRequest searchRequest = new SearchRequest(logIndexPrefix + "*"); searchRequest.types(EVENT_DOC_TYPE); searchRequest.source(searchSourceBuilder); SearchResponse response = elasticSearchClient.search(searchRequest); return mapEventExecutionsResponse(response); } catch (Exception e) { logger.error("Failed to get executions for event: {}", event, e); throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e); } }
Example #30
Source File: ElasticSearchRestDAOV5.java From conductor with Apache License 2.0 | 5 votes |
@Override public List<Message> getMessages(String queue) { try { Expression expression = Expression.fromString("queue='" + queue + "'"); QueryBuilder queryBuilder = expression.getFilterBuilder(); BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder); QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*"); BoolQueryBuilder query = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery); // Create the searchObjectIdsViaExpression source SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(query); searchSourceBuilder.sort(new FieldSortBuilder("created").order(SortOrder.ASC)); // Generate the actual request to send to ES. SearchRequest searchRequest = new SearchRequest(logIndexPrefix + "*"); searchRequest.types(MSG_DOC_TYPE); searchRequest.source(searchSourceBuilder); SearchResponse response = elasticSearchClient.search(searchRequest); return mapGetMessagesResponse(response); } catch (Exception e) { logger.error("Failed to get messages for queue: {}", queue, e); throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e); } }