本文整理汇总了Java中org.springframework.data.elasticsearch.core.query.SearchQuery类的典型用法代码示例。如果您正苦于以下问题:Java SearchQuery类的具体用法?Java SearchQuery怎么用?Java SearchQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SearchQuery类属于org.springframework.data.elasticsearch.core.query包,在下文中一共展示了SearchQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: searchCity
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Override
public List<City> searchCity(Integer pageNumber,
Integer pageSize,
String searchContent) {
// 分页参数
Pageable pageable = new PageRequest(pageNumber, pageSize);
// Function Score Query
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
.add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("cityname", searchContent)),
ScoreFunctionBuilders.weightFactorFunction(1000))
.add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("description", searchContent)),
ScoreFunctionBuilders.weightFactorFunction(100));
// 创建搜索 DSL 查询
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withPageable(pageable)
.withQuery(functionScoreQueryBuilder).build();
LOGGER.info("\n searchCity(): searchContent [" + searchContent + "] \n DSL = \n " + searchQuery.getQuery().toString());
Page<City> searchPageResults = cityRepository.search(searchQuery);
return searchPageResults.getContent();
}
开发者ID:nickleeguan,项目名称:springboot-learning-example-master,代码行数:25,代码来源:CityESServiceImpl.java
示例2: fetchReleaseRecord
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
private CmsRelease fetchReleaseRecord(String nsPath, Date ts, int genTime) throws InterruptedException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(CmsConstants.SEARCH_TS_PATTERN);
Thread.sleep(3000);
SearchQuery latestRelease = new NativeSearchQueryBuilder()
.withIndices("cms-*")
.withTypes("release").withFilter(
FilterBuilders.andFilter(
FilterBuilders.queryFilter(QueryBuilders.termQuery("nsPath.keyword", nsPath)),
FilterBuilders.queryFilter(QueryBuilders.rangeQuery("created").
from(simpleDateFormat.format(DateUtils.addMinutes(ts, -(genTime + 10)))).
to(simpleDateFormat.format(ts))))).
withSort(SortBuilders.fieldSort("created").order(SortOrder.DESC)).build();
List<CmsReleaseSearch> ciList = indexer.getTemplate().queryForList(latestRelease, CmsReleaseSearch.class);
if (!ciList.isEmpty()) {
return ciList.get(0);
}
throw new RuntimeException("Cant find bom release for deployment plan generation event");
}
开发者ID:oneops,项目名称:oneops,代码行数:20,代码来源:DeploymentPlanProcessor.java
示例3: getTopicByCateAndUser
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的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 ;
}
开发者ID:uckefu,项目名称:uckefu,代码行数:21,代码来源:TopicRepositoryImpl.java
示例4: searchCity
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Override
public List<City> searchCity(Integer pageNumber, Integer pageSize, String searchContent) {
// 校验分页参数
if (pageSize == null || pageSize <= 0) {
pageSize = PAGE_SIZE;
}
if (pageNumber == null || pageNumber < DEFAULT_PAGE_NUMBER) {
pageNumber = DEFAULT_PAGE_NUMBER;
}
LOGGER.info("\n searchCity: searchContent [" + searchContent + "] \n ");
// 构建搜索查询
SearchQuery searchQuery = getCitySearchQuery(pageNumber,pageSize,searchContent);
LOGGER.info("\n searchCity: searchContent [" + searchContent + "] \n DSL = \n " + searchQuery.getQuery().toString());
Page<City> cityPage = cityRepository.search(searchQuery);
return cityPage.getContent();
}
开发者ID:JeffLi1993,项目名称:springboot-learning-example,代码行数:23,代码来源:CityESServiceImpl.java
示例5: getCitySearchQuery
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
/**
* 根据搜索词构造搜索查询语句
*
* 代码流程:
* - 权重分查询
* - 短语匹配
* - 设置权重分最小值
* - 设置分页参数
*
* @param pageNumber 当前页码
* @param pageSize 每页大小
* @param searchContent 搜索内容
* @return
*/
private SearchQuery getCitySearchQuery(Integer pageNumber, Integer pageSize,String searchContent) {
// 短语匹配到的搜索词,求和模式累加权重分
// 权重分查询 https://www.elastic.co/guide/cn/elasticsearch/guide/current/function-score-query.html
// - 短语匹配 https://www.elastic.co/guide/cn/elasticsearch/guide/current/phrase-matching.html
// - 字段对应权重分设置,可以优化成 enum
// - 由于无相关性的分值默认为 1 ,设置权重分最小值为 10
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
.add(QueryBuilders.matchPhraseQuery("name", searchContent),
ScoreFunctionBuilders.weightFactorFunction(1000))
.add(QueryBuilders.matchPhraseQuery("description", searchContent),
ScoreFunctionBuilders.weightFactorFunction(500))
.scoreMode(SCORE_MODE_SUM).setMinScore(MIN_SCORE);
// 分页参数
Pageable pageable = new PageRequest(pageNumber, pageSize);
return new NativeSearchQueryBuilder()
.withPageable(pageable)
.withQuery(functionScoreQueryBuilder).build();
}
开发者ID:JeffLi1993,项目名称:springboot-learning-example,代码行数:34,代码来源:CityESServiceImpl.java
示例6: processNotificationMsg
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
/**
* Update ops notifications to CIs
*
* @param notificationMsg notification message to process
*/
private void processNotificationMsg(CmsNotificationSearch notificationMsg) {
String id = String.valueOf(notificationMsg.getCmsId());
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withIndices(indexer.getIndexName())
.withTypes("ci").withQuery(queryStringQuery(id).field("ciId"))
.build();
List<CmsCISearch> ciList = indexer.getTemplate().queryForList(searchQuery, CmsCISearch.class);
if (!ciList.isEmpty()) {
CmsCISearch ciSearch = ciList.get(0);
if ("bom.Compute".equals(ciSearch.getCiClassName())) {
String hypervisor = ciSearch.getCiAttributes().get("hypervisor");
if (hypervisor != null) {
notificationMsg.setHypervisor(hypervisor);
}
}
ciSearch.setOps(notificationMsg);
indexer.index(id, "ci", GSON_ES.toJson(ciSearch));
logger.info("updated ops notification for ci id::" + id);
} else {
logger.warn("ci record not found for id::" + id);
}
}
开发者ID:oneops,项目名称:oneops,代码行数:31,代码来源:NotificationMessageProcessor.java
示例7: findByOptimal
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Override
public List<TopicComment> findByOptimal(String dataid) {
List<TopicComment> commentList = null ;
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("dataid" , dataid)).withQuery(termQuery("optimal" , true)).build();
if(elasticsearchTemplate.indexExists(TopicComment.class)){
commentList = elasticsearchTemplate.queryForList(searchQuery, TopicComment.class);
}
return commentList ;
}
开发者ID:uckefu,项目名称:uckefu,代码行数:10,代码来源:TopicCommentRepositoryImpl.java
示例8: findByCon
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的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 ;
}
开发者ID:uckefu,项目名称:uckefu,代码行数:18,代码来源:UKeFuRepositoryImpl.java
示例9: findByCon
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的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 ;
}
开发者ID:uckefu,项目名称:uckefu,代码行数:17,代码来源:TopicRepositoryImpl.java
示例10: searchCity
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Override
public List<City> searchCity(Integer pageNumber,
Integer pageSize,
String searchContent) {
// 分页参数
Pageable pageable = new PageRequest(pageNumber, pageSize);
// Function Score Query
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
.add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("cityname", searchContent)),
ScoreFunctionBuilders.weightFactorFunction(1000))
.add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("description", searchContent)),
ScoreFunctionBuilders.weightFactorFunction(100));
// 创建搜索 DSL 查询
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withPageable(pageable)
.withQuery(functionScoreQueryBuilder).build();
LOGGER.info("\n searchCity(): searchContent [" + searchContent + "] \n DSL = \n " + searchQuery.getQuery().toString());
Page<City> searchPageResults = cityRepository.search(searchQuery);
return searchPageResults.getContent();
}
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:25,代码来源:CityServiceImpl.java
示例11: testForElasticsearchTemplate
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Test
public void testForElasticsearchTemplate() throws Exception {
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
SearchQuery searchQuery = new NativeSearchQuery(
QueryBuilders.matchAllQuery()
);
elasticsearchTemplate.queryForList(searchQuery, GeoBoundingBox.class);
}
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:9,代码来源:MatchAllQueryDemo.java
示例12: findWithHighlightedSummary
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Override
public Page<File> findWithHighlightedSummary(Pageable pageable, String query, List<String> version, List<String> project) {
//QueryBuilder searchQuery = Queries.constructQuery(query);
//return elasticsearchTemplate.queryForPage(new NativeSearchQuery(searchQuery), File.class, new ResultHighlightMapper());
NativeSearchQueryBuilder nativeQuery = Queries.constructQueryWithHighlight(query, pageable, 3);
BoolQueryBuilder ensembleVersion = QueryBuilders.boolQuery();
BoolQueryBuilder ensembleProjet = QueryBuilders.boolQuery();
if (version != null && !version.isEmpty()) {
ensembleVersion = ensembleVersion.should(QueryBuilders.termsQuery("version.raw", version));
}
if (project != null && !project.isEmpty()) {
ensembleProjet = ensembleProjet.should(QueryBuilders.termsQuery("project.raw", project));
}
nativeQuery = nativeQuery.withFilter(QueryBuilders.boolQuery().must(ensembleVersion).must(ensembleProjet));
log.debug("query : {}", nativeQuery.toString());
SearchQuery searchQuery = nativeQuery.build();
log.debug("query : {}", searchQuery.getQuery());
log.debug("filter: {}", searchQuery.getFilter());
return elasticsearchTemplate.queryForPage(searchQuery, File.class, new ResultHighlightMapper());
// SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
}
开发者ID:klask-io,项目名称:klask-io,代码行数:27,代码来源:CustomSearchRepositoryImpl.java
示例13: shouldReturnAggregatedResponseForGivenSearchQuery
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Test
public void shouldReturnAggregatedResponseForGivenSearchQuery() {
// given
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery())
.withSearchType(QUERY_THEN_FETCH)
.withPageable(PageRequest.of(0, 1))
.withIndices("articles").withTypes("article")
.addAggregation(terms("subjects").field("subject"))
.build();
// when
AggregatedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
// then
TermsAggregation subjectAgg = result.getAggregation("subjects", TermsAggregation.class);
assertThat(subjectAgg, is(notNullValue()));
assertThat(subjectAgg, is(notNullValue()));
assertThat(subjectAgg.getBuckets().get(0).getKey(), is("computing"));
assertThat(subjectAgg.getBuckets().get(0).getCount(), is(3L));
assertThat(subjectAgg.getBuckets().get(1).getKey(), is("accounting"));
assertThat(subjectAgg.getBuckets().get(1).getCount(), is(1L));
}
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:24,代码来源:ElasticsearchTemplateAggregationTests.java
示例14: findAll
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Override
public Iterable<T> findAll(Iterable<ID> ids) {
Assert.notNull(ids, "ids can't be null.");
SearchQuery query = new NativeSearchQueryBuilder() //
.withQuery(and(idsQuery().ids(idsArray(ids)), aclFilter())) //
.build();
return elasticsearchOperations.queryForList(query, getEntityClass());
}
开发者ID:lordlothar99,项目名称:strategy-spring-security-acl,代码行数:10,代码来源:AclElasticsearchRepository.java
示例15: findPropertiesByLocation
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Override
public List<Property> findPropertiesByLocation(final GeoPoint geoPoint, Double distance, final SortOrder sortOrder) {
GeoDistanceFilterBuilder filter = FilterBuilders.geoDistanceFilter("location").point(geoPoint.getLat(), geoPoint.getLon())
.distance(distance, DistanceUnit.KILOMETERS);
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withFilter(filter)
.withSort(
SortBuilders.geoDistanceSort("location").point(geoPoint.getLat(), geoPoint.getLon())
.order(sortOrder == null ? SortOrder.ASC : sortOrder)).build();
searchQuery.addIndices("searchahouse");
searchQuery.addTypes("property");
List<Property> properties = this.elasticsearchOperations.queryForList(searchQuery, Property.class);
return properties;
}
开发者ID:gustavoorsi,项目名称:searchahouse.com,代码行数:19,代码来源:PropertyServiceImpl.java
示例16: search
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@RequestMapping(value = "/search", method = RequestMethod.GET)
public Page<PoliceTicker> search(@RequestParam String query,
@PageableDefault(direction = Direction.DESC, sort = "datePublished") final Pageable pageable) {
logger.info("query: {}", query);
Page<PoliceTicker> result;
if (!query.isEmpty()) {
query = query.toLowerCase();
final List<String> splitToList = Splitter.on(CharMatcher.WHITESPACE).splitToList(query);
final SearchQuery sq = new NativeSearchQueryBuilder().withPageable(pageable)
.withQuery(createFulltextSearchQueryBuilder(splitToList)).build();
result = elasticsearchTemplate.queryForPage(sq, PoliceTicker.class);
} else {
result = getx(pageable);
}
return result;
}
开发者ID:CodeforLeipzig,项目名称:lvz-viz,代码行数:19,代码来源:PoliceTickerController.java
示例17: fetchprocedureRecord
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
private CmsOpsProcedureSearch fetchprocedureRecord(long procedureId) {
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withIndices("cms-2*")
.withTypes(OPSPROCEDURE).withQuery(queryStringQuery(String.valueOf(procedureId)).field("procedureId"))
.build();
List<CmsOpsProcedureSearch> esProcedureList = indexer.getTemplate().queryForList(searchQuery, CmsOpsProcedureSearch.class);
return !esProcedureList.isEmpty() ? esProcedureList.get(0) : null;
}
开发者ID:oneops,项目名称:oneops,代码行数:10,代码来源:OpsProcMessageProcessor.java
示例18: fetchDeploymentRecord
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
private CmsDeploymentSearch fetchDeploymentRecord(long deploymentId) {
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withIndices("cms-2*")
.withTypes(DEPLOYMENT).withQuery(queryStringQuery(String.valueOf(deploymentId)).field("deploymentId"))
.build();
List<CmsDeploymentSearch> esDeploymentList = indexer.getTemplate().queryForList(searchQuery, CmsDeploymentSearch.class);
if (esDeploymentList.size() > 1) {
cleanOldDeployment(esDeploymentList.get(0).getDeploymentId());
}
return !esDeploymentList.isEmpty() ? esDeploymentList.get(0) : null;
}
开发者ID:oneops,项目名称:oneops,代码行数:13,代码来源:DeploymentMessageProcessor.java
示例19: findByDataid
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的package包/类
@Override
public FacetedPage<TopicComment> findByDataid(String id , int p , int ps) {
FacetedPage<TopicComment> pages = null ;
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("dataid" , id)).withSort(new FieldSortBuilder("optimal").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC)).build().setPageable(new PageRequest(p, ps)) ;
if(elasticsearchTemplate.indexExists(TopicComment.class)){
pages = elasticsearchTemplate.queryForPage(searchQuery, TopicComment.class);
}
return pages ;
}
开发者ID:uckefu,项目名称:uckefu,代码行数:10,代码来源:TopicCommentRepositoryImpl.java
示例20: findByCon
import org.springframework.data.elasticsearch.core.query.SearchQuery; //导入依赖的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 ;
}
开发者ID:uckefu,项目名称:uckefu,代码行数:17,代码来源:TopicCommentRepositoryImpl.java
注:本文中的org.springframework.data.elasticsearch.core.query.SearchQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论