当前位置: 首页>>代码示例>>Java>>正文


Java FilterBuilders类代码示例

本文整理汇总了Java中org.elasticsearch.index.query.FilterBuilders的典型用法代码示例。如果您正苦于以下问题:Java FilterBuilders类的具体用法?Java FilterBuilders怎么用?Java FilterBuilders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FilterBuilders类属于org.elasticsearch.index.query包,在下文中一共展示了FilterBuilders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchReleaseRecord

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的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

示例2: getRunningInstancesWithFields

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
@Override
public Iterator<EsQueryResult> getRunningInstancesWithFields(String[] includeFields)
    throws Exception {

  QueryBuilder queryBuilder = QueryBuilders.filteredQuery(
      QueryBuilders.termQuery("state", "running"),
      FilterBuilders.termFilter("state", "running"));

  ScrollableResponse<List<EsQueryResult>> response = this.retrieveScrollByQuery(queryBuilder,
      includeFields, BATCHSIZE,
      str -> insertMapper.readValue(str, EsQueryResult.class));

  EsIterator<EsQueryResult>
      iterator =
      new EsIterator<>(response, r -> scrollNext(r.getContinousToken(),
          str -> insertMapper.readValue(str, EsQueryResult.class)));

  return iterator;
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:20,代码来源:EsInstanceStore.java

示例3: retrieveScrollByField

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
protected <E extends EsDocument> ScrollableResponse<List<E>> retrieveScrollByField(
    String field, Object value, String[] includeFields, int size,
    ThrowingFunction<String, E> createFunc)
    throws Exception {

  Preconditions.checkArgument(size > 0);

  SearchRequestBuilder builder = esClient.prepareSearch()
      .setIndices(getIndexName()).setTypes(getDocTypeName())
      .setScroll(new TimeValue(SCROLLDEFAULTTIMEOUT))
      .setSize(size)
      .setQuery(QueryBuilders
          .filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termsFilter(field, value)))
      .setFetchSource(includeFields, null).setVersion(true);

  SearchResponse response = builder.execute().actionGet();
  return convertToScrollableResponse(response, createFunc);
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:19,代码来源:EsStore.java

示例4: getFilterBuilder

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
private FilterBuilder getFilterBuilder(SearchQuery searchQuery) {
    Map<String, Object> filterMap = searchQuery.getFilter();
    List<FilterBuilder> filterBuilders = new ArrayList<>();

    if (filterMap != null && filterMap.size() > 0) {
        for (String key : filterMap.keySet()) {
            filterBuilders.add(FilterBuilders.termFilter(key, filterMap.get(key)));
        }
    }

    if (searchQuery.getPriceFrom() != null || searchQuery.getPriceTo() != null)
        filterBuilders.add(
            FilterBuilders.rangeFilter("price").from(searchQuery.getPriceFrom()).to(searchQuery.getPriceTo()));

    if (searchQuery.isShowEvent()) {
        filterBuilders.add(FilterBuilders.termFilter("is_special", true));
    }

    if (searchQuery.isShowSale()) {
        filterBuilders.add(FilterBuilders.termFilter("is_sale", true));
    }

    return FilterBuilders.andFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:25,代码来源:DefaultSearchService.java

示例5: makeFilterBuilder

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
/**
 * 获取过滤器
 * 
 * @return
 */
public BoolFilterBuilder makeFilterBuilder(SearchRequestBuilder srb) {
    // 过滤器
    BoolFilterBuilder boolFilterBuilder = FilterBuilders.boolFilter();
    if (request.getSafeFilterScript().size() > 0) {
        ScriptFilterBuilder filter;
        for (EsFilterScript filterScript : request.getSafeFilterScript()) {
            filter = FilterBuilders.scriptFilter(filterScript.getScript());
            if (filterScript.getScriptParams() != null
                    && filterScript.getScriptParams().size() > 0) {
                filter.params(filterScript.getScriptParams());
            }
            boolFilterBuilder.should(filter);
        }
        srb.setPostFilter(boolFilterBuilder);
    }
    return boolFilterBuilder;
}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:23,代码来源:EsQueryBuilder.java

示例6: getTraceCompletionCount

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
private long getTraceCompletionCount(String tenantId, Criteria criteria, boolean onlyFaulty) {
    String index = client.getIndex(tenantId);
    if (!refresh(index)) {
        return 0;
    }

    BoolQueryBuilder query = buildQuery(criteria, ElasticsearchUtil.TRANSACTION_FIELD, CompletionTime.class);
    SearchRequestBuilder request = getTraceCompletionRequest(index, criteria, query, 0);

    if (onlyFaulty) {
        FilterBuilder filter = FilterBuilders.queryFilter(QueryBuilders.boolQuery()
                .must(QueryBuilders.matchQuery(ElasticsearchUtil.PROPERTIES_NAME_FIELD, Constants.PROP_FAULT)));
        request.setPostFilter(FilterBuilders.nestedFilter("properties", filter));
    }

    SearchResponse response = request.execute().actionGet();
    if (response.isTimedOut()) {
        msgLog.warnQueryTimedOut();
        return 0;
    } else {
        return response.getHits().getTotalHits();
    }
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:24,代码来源:AnalyticsServiceElasticsearch.java

示例7: getContributionsByCandName

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
public void getContributionsByCandName(Client client, String candName, int i)
{
	QueryBuilder matchQuery = QueryBuilders.matchQuery("candNm", candName);
	FilterBuilder contribRangeFilter = FilterBuilders.rangeFilter("contbReceiptAmt").gte(i);
	StatisticalFacetBuilder facet = FacetBuilders.statisticalFacet("stat1").field("contbReceiptAmt");
	SearchRequestBuilder request = client.prepareSearch("contributions")
			.addSort(SortBuilders.fieldSort("contbReceiptAmt").order(SortOrder.DESC))
			.setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(matchQuery).setPostFilter(contribRangeFilter)
			.addFacet(facet).setFrom(0).setSize(100)
			.addFields("contbrNm", "candNm", "contbrEmployer", "contbReceiptAmt");
	System.out.println("SEARCH QUERY: " + request.toString());

	SearchResponse response = request.execute().actionGet();
	SearchHits searchHits = response.getHits();
	SearchHit[] hits = searchHits.getHits();
	for (SearchHit hit : hits)
	{
		Map<String, SearchHitField> fields = hit.getFields();
		System.out.println(hit.getId() + ", contbrEmployer=" + fields.get("contbrEmployer").getValue().toString());
	}
}
 
开发者ID:cplutte,项目名称:bts,代码行数:22,代码来源:ElasticTest.java

示例8: makeFilterList

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
private List<FilterBuilder> makeFilterList(BTSConfigItem configItem, BTSObject object) {

		Set<String> referenceTypes = configurationController.getReferenceTypesSet(object, configItem);
		
		List<FilterBuilder> filters = new ArrayList<FilterBuilder>();
		for (String ref : referenceTypes) {
			if (ref.contains(BTSConstants.OWNER_REFERENCED_TYPES_PATH_SEPERATOR)) {
				String[] split = ref.split("\\.");
				if (split.length == 2) {
					filters.add(FilterBuilders.termFilter(new String("type"),
							ref));
				} else if (split.length == 3) {
					filters.add(FilterBuilders.termFilter(
							new String("subtype"), ref));
				}

			}

		}
		return filters;

	}
 
开发者ID:cplutte,项目名称:bts,代码行数:23,代码来源:GeneralBTSObjectControllerImpl.java

示例9: testQuery

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
@Test
@Ignore
public void testQuery() throws Exception {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    FilterBuilder filter = FilterBuilders.boolFilter()
            .must(FilterBuilders.termFilter("attributes.league", "Flashback Event HC (IC002)"))
            .must(FilterBuilders.termFilter("attributes.equipType", "Jewel"))
            .must(FilterBuilders.rangeFilter("modsTotal.#% increased maximum Life").gt(4))
            .must(FilterBuilders.termFilter("shop.verified", "yes"))
           // .must(FilterBuilders.termFilter("attributes.rarity", "Magic"))
            ;

    searchSourceBuilder
            .query(QueryBuilders.filteredQuery(QueryBuilders.boolQuery().minimumNumberShouldMatch(2)
                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Area Damage"))
                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Projectile Damage"))
                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Chaos Damage")), filter))
            .sort("_score");
    SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
	List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
	hits.stream().map(hit -> hit.source).forEach(System.out::println);
}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:23,代码来源:ExileToolsSearchClientTest.java

示例10: testExecuteMjolnerUsingFilters

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
/**
	 * As per ES documentation/tome, the best way to do our search is via Filters
	 */
	@Test
	@Ignore
	public void testExecuteMjolnerUsingFilters() throws Exception {
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		List<FilterBuilder> filters = new LinkedList<>();
		
		filters.add(FilterBuilders.termFilter("attributes.league", "Flashback Event (IC001)"));
//		filters.add(FilterBuilders.termFilter("info.name", "Mjolner"));
		filters.add(FilterBuilders.termFilter("info.name", "Hegemony's Era"));
		filters.add(FilterBuilders.rangeFilter("properties.Weapon.Physical DPS").from(400));
		
		FilterBuilder filter = FilterBuilders.andFilter(filters.toArray(new FilterBuilder[filters.size()]));
		searchSourceBuilder.query(QueryBuilders.filteredQuery(null, filter));
		searchSourceBuilder.size(100);
		SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
		List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
		for (Hit<ExileToolsHit, Void> hit : hits) {
//			logger.info(hit.source.toString());
//			hit.source.getQuality().ifPresent( q -> logger.info(q.toString()) );
			hit.source.getPhysicalDPS().ifPresent( q -> logger.info(q.toString()) );
//			logger.info(hit.source.toString());
//			logger.info(hit.source.getRequirements().getLevel().toString());
//			logger.info(hit.source.getExplicitMods().toString());
		}
	}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:29,代码来源:ExileToolsSearchClientTest.java

示例11: testDistinctItemTypeValues

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
@Test
@Ignore
public void testDistinctItemTypeValues() throws Exception {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
	searchSourceBuilder.query(QueryBuilders.filtered(null, FilterBuilders.boolFilter()
			.must(FilterBuilders.termFilter("attributes.itemType", "Card"))
			));
	searchSourceBuilder.aggregation(AggregationBuilders.terms("rarities").field("info.name")
			.size(0));
	SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
	logger.info(result.getJsonString());
	System.out.println("-------");
	result.getAggregations().getTermsAggregation("rarities").getBuckets().stream()
	.map(e -> e.getKey())
	.sorted()
	.forEach(k -> System.out.println(k));
}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:18,代码来源:ExileToolsSearchClientTest.java

示例12: findPropertiesByLocation

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的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

示例13: testQuery

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
@Test
	@Ignore
	public void testQuery() throws Exception {
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
	    FilterBuilder filter = FilterBuilders.boolFilter()
	            .must(FilterBuilders.termFilter("attributes.league", "Flashback Event HC (IC002)"))
	            .must(FilterBuilders.termFilter("attributes.equipType", "Jewel"))
	            .must(FilterBuilders.rangeFilter("modsTotal.#% increased maximum Life").gt(4))
	            .must(FilterBuilders.termFilter("shop.verified", "yes"))
	           // .must(FilterBuilders.termFilter("attributes.rarity", "Magic"))
	            ;

	    searchSourceBuilder
	            .query(QueryBuilders.filteredQuery(QueryBuilders.boolQuery().minimumNumberShouldMatch(2)
	                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Area Damage"))
	                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Projectile Damage"))
	                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Chaos Damage")), filter))
	            .sort("_score");
//	    SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
//		List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
//		hits.stream().map(hit -> hit.source).forEach(System.out::println);
	}
 
开发者ID:bluemarlinexile,项目名称:bluemarlin,代码行数:23,代码来源:ExileToolsSearchClientTest.java

示例14: testExecuteMjolnerUsingFilters

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
/**
	 * As per ES documentation/tome, the best way to do our search is via Filters
	 */
	@Test
	@Ignore
	public void testExecuteMjolnerUsingFilters() throws Exception {
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		List<FilterBuilder> filters = new LinkedList<>();
		
		filters.add(FilterBuilders.termFilter("attributes.league", "Flashback Event (IC001)"));
//		filters.add(FilterBuilders.termFilter("info.name", "Mjolner"));
		filters.add(FilterBuilders.termFilter("info.name", "Hegemony's Era"));
		filters.add(FilterBuilders.rangeFilter("properties.Weapon.Physical DPS").from(400));
		
		FilterBuilder filter = FilterBuilders.andFilter(filters.toArray(new FilterBuilder[filters.size()]));
		searchSourceBuilder.query(QueryBuilders.filteredQuery(null, filter));
		searchSourceBuilder.size(100);
//		SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
//		List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
//		for (Hit<ExileToolsHit, Void> hit : hits) {
////			logger.info(hit.source.toString());
////			hit.source.getQuality().ifPresent( q -> logger.info(q.toString()) );
//			hit.source.getPhysicalDPS().ifPresent( q -> logger.info(q.toString()) );
////			logger.info(hit.source.toString());
////			logger.info(hit.source.getRequirements().getLevel().toString());
////			logger.info(hit.source.getExplicitMods().toString());
//		}
	}
 
开发者ID:bluemarlinexile,项目名称:bluemarlin,代码行数:29,代码来源:ExileToolsSearchClientTest.java

示例15: getBaseFilterBuilder

import org.elasticsearch.index.query.FilterBuilders; //导入依赖的package包/类
private FilterBuilder getBaseFilterBuilder(String facetName, String fieldValue)
    {
        if(facetName.startsWith(SearchFacetName.SEARCH_FACET_TYPE_FACET_PREFIX))
        {
            return getTermFilter(SearchFacetName.CATEGORIES_FIELD_PREFIX + facetName + "." + SearchDocumentFieldName.FACETFILTER.getFieldName(), fieldValue.toLowerCase());
        }
        else if(facetName.startsWith(SearchFacetName.PRODUCT_PRICE_RANGE.getCode()))
        {
            return FilterBuilders.rangeFilter(SearchDocumentFieldName.PRICE.getFieldName()).includeLower(true).includeUpper(false).from(fieldValue.split("-")[0]).to(fieldValue.split("-")[1]);
        }
        else
        {
            return FilterBuilders.termFilter(facetName, fieldValue);
        }
//        return null;
    }
 
开发者ID:jaibeermalik,项目名称:elasticsearch-tutorial,代码行数:17,代码来源:ProductQueryServiceImpl.java


注:本文中的org.elasticsearch.index.query.FilterBuilders类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。