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


Java FilterBuilder类代码示例

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


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

示例1: getFilterBuilder

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

示例2: getTraceCompletionCount

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

示例3: getContributionsByCandName

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

示例4: makeFilterList

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

示例5: itemTypesFilter

import org.elasticsearch.index.query.FilterBuilder; //导入依赖的package包/类
private Optional<OrFilterBuilder> itemTypesFilter() {
	if (!itemTypesPanes.getSelected().isEmpty()) {
		List<FilterBuilder> itemTypeFilters = itemTypesPanes.getSelected()
				.stream()
				.map(it -> {
					FilterBuilder itFilter = termFilter("attributes.itemType", it.itemType());
					if (it.equipType() != null) {
						itFilter = andFilter(itFilter, termFilter("attributes.equipType", it.equipType()));
					}
					return itFilter;
				})
				.collect(Collectors.toList());
		return Optional.of(orFilter(toArray(itemTypeFilters, FilterBuilder.class)));
	}
	return Optional.empty();
}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:17,代码来源:ControlPane.java

示例6: testQuery

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

示例7: testExecuteMjolnerUsingFilters

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

示例8: findUniqueTerms

import org.elasticsearch.index.query.FilterBuilder; //导入依赖的package包/类
final protected <T> IPage<T> findUniqueTerms(FilterBuilder filter, AggregationBuilder aggregation, String index, String documentType, Class<T> javaType) {
    SearchResponse response = client.prepareSearch(index)
            .setTypes(documentType)
            .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filter))
            .addAggregation(aggregation)
            .setSize(0)
            .get();

    Terms results = response.getAggregations().get(aggregation.getName());


    IPage page = Page.<T>of(Iterables.transform(results.getBuckets(), new Function<Terms.Bucket, T>() {
        @Override
        public T apply(Terms.Bucket input) {
            return (T) input.getKey();
        }
    }));
    page.setPageSize(page.size());
    page.setPageNumber(1);
    page.setTotalElements(page.size());

    return page;

}
 
开发者ID:bpatters,项目名称:eservice,代码行数:25,代码来源:AbstractElasticsearchDAO.java

示例9: testQuery

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

示例10: testExecuteMjolnerUsingFilters

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

示例11: getBaseFilterBuilder

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

示例12: getBaseFilterBuilder

import org.elasticsearch.index.query.FilterBuilder; //导入依赖的package包/类
private FilterBuilder getBaseFilterBuilder(final String facetName, final 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-akka,代码行数:20,代码来源:ProductQueryServiceImpl.java

示例13: fromValueType

import org.elasticsearch.index.query.FilterBuilder; //导入依赖的package包/类
private static FilterBuilder fromValueType(String field, String value, int valueType){
	if(value.contains("*") || value.contains("?")){
		if( value.length() > 1 && value.indexOf('*') == (value.length()-1))
			return FilterBuilders.prefixFilter(field, value.substring(0, value.length()-1));
		else
			return FilterBuilders.queryFilter(QueryBuilders.wildcardQuery(field, value));
	}
	
	switch(valueType){
	case AST_TermExpression.TERM:
		return FilterBuilders.termFilter(field, value);
	case AST_TermExpression.PHRASE:
		/*for(byte b: value.getBytes()){
			System.out.printf("0x%02X ", b);		        
		}*/
		return FilterBuilders.queryFilter(QueryBuilders.matchPhraseQuery(field, value));
	}
	return null;
}
 
开发者ID:huangchen007,项目名称:elasticsearch-rest-command,代码行数:20,代码来源:AST_Search.java

示例14: search

import org.elasticsearch.index.query.FilterBuilder; //导入依赖的package包/类
@Override
public <T> List<T> search(Class<T> clazz, @Nullable QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder) {
    SearchRequestBuilder builder = getSearchRequestBuilder(clazz);
    if (queryBuilder != null) {
        builder.setQuery(queryBuilder);
    }

    if (filterBuilder != null) {
        builder.setPostFilter(filterBuilder);
    }

    if (logger.isDebugEnabled()) {
        String queryStr = "";
        String filterStr = "";
        if (queryBuilder != null) {
            queryStr = queryBuilder.buildAsBytes().toUtf8();
        }
        if (filterBuilder != null) {
            filterStr = filterBuilder.buildAsBytes().toUtf8();
        }
        logger.debug("Search for class: {}, query: {}, filter: {}", clazz.getSimpleName(), queryStr, filterStr);
    }

    return search(clazz, builder);
}
 
开发者ID:kzwang,项目名称:elasticsearch-osem,代码行数:26,代码来源:ElasticSearchSearcherImpl.java

示例15: getBaseFilterBuilder

import org.elasticsearch.index.query.FilterBuilder; //导入依赖的package包/类
private FilterBuilder getBaseFilterBuilder(final String facetName,
		final 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,项目名称:searchanalytics-bigdata,代码行数:24,代码来源:ProductQueryServiceImpl.java


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