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


Java FilterBuilders.termFilter方法代码示例

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


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

示例1: 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

示例2: getBaseFilterBuilder

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

示例3: fromValueType

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

示例4: getBaseFilterBuilder

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

示例5: testTermFilter

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Test
public void testTermFilter() {
  FilterBuilder termFilter = FilterBuilders.termFilter("text_entry", "havoc");

  QueryBuilder filteredQuery =
      QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), termFilter);

  SearchResponse response = srb.setQuery(filteredQuery).execute().actionGet();

  // read response
  long totalMatched = response.getHits().getTotalHits();
  System.out.println("Total matched: " + totalMatched);
}
 
开发者ID:destiny1020,项目名称:elasticsearch-java-client-examples,代码行数:14,代码来源:QueryDslFilterOfficial.java

示例6: buildSearchForIndexedDocumentsNotUpdatedAfter

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Override
public void buildSearchForIndexedDocumentsNotUpdatedAfter(SearchRequestBuilder srb, String spaceKey, Date date) {
	FilterBuilder filterTime = FilterBuilders.rangeFilter("_timestamp").lt(date);
	FilterBuilder filterSpaceKey = FilterBuilders.termFilter(indexFieldForSpaceKey, spaceKey);
	FilterBuilder filterSource = FilterBuilders.termFilter(indexFieldForRiverName, riverName);
	FilterBuilder filter = FilterBuilders.boolFilter().must(filterTime, filterSpaceKey, filterSource);
	srb.setQuery(QueryBuilders.matchAllQuery()).addField("_id").setPostFilter(filter);
	if (commentIndexingMode.isExtraDocumentIndexed())
		srb.setTypes(issueTypeName, commentTypeName);
	else
		srb.setTypes(issueTypeName);
}
 
开发者ID:searchisko,项目名称:elasticsearch-river-remote,代码行数:13,代码来源:DocumentWithCommentsIndexStructureBuilder.java

示例7: buildSearchForIndexedDocumentsWithRemoteId

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Override
public void buildSearchForIndexedDocumentsWithRemoteId(SearchRequestBuilder srb, String spaceKey, String remoteId) {
	FilterBuilder filterRemoteId = FilterBuilders.termFilter(indexFieldForRemoteDocumentId, remoteId);
	FilterBuilder filterSpaceKey = FilterBuilders.termFilter(indexFieldForSpaceKey, spaceKey);
	FilterBuilder filterSource = FilterBuilders.termFilter(indexFieldForRiverName, riverName);
	FilterBuilder filter = FilterBuilders.boolFilter().must(filterRemoteId, filterSpaceKey, filterSource);
	srb.setQuery(QueryBuilders.matchAllQuery()).addField("_id").setPostFilter(filter);
	if (commentIndexingMode.isExtraDocumentIndexed())
		srb.setTypes(issueTypeName, commentTypeName);
	else
		srb.setTypes(issueTypeName);
}
 
开发者ID:searchisko,项目名称:elasticsearch-river-remote,代码行数:13,代码来源:DocumentWithCommentsIndexStructureBuilder.java

示例8: buildQuery

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Override
public FilterBuilder buildQuery(QueryNode queryNode) {
    if (queryNode == null)
        return null;
    if (queryNode.getType().equals(QueryNodeType.BOOLEAN)) {
        List<FilterBuilder> filterBuilders = new ArrayList<>();
        for (QueryNode node : queryNode.getNodes()) {
            filterBuilders.add(buildQuery(node));
        }
        if (queryNode.getOperator().equals(AND)) {
            FilterBuilder andFilterBuilder = FilterBuilders.andFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
            return andFilterBuilder;
        } else {
            FilterBuilder orFilterBuilder = FilterBuilders.orFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
            return orFilterBuilder;
        }
    } else {
        if (queryNode.getValue() != null && queryNode.getValue().getAttribute() != null) {
            String key = ATT_PREFIX + Strings.slugify(queryNode.getValue().getAttribute().getCode()).replace(Char.MINUS, Char.UNDERSCORE) + HASH_SUFFIX;
            if (queryNode.getValue().getOptionIds() != null && queryNode.getValue().getOptionIds().size() > 1) {
                List<String> values = new ArrayList<>();
                for (Id id : queryNode.getValue().getOptionIds()) {
                    values.add(Str.UNDERSCORE_2X + id + Str.UNDERSCORE_2X);
                }
                return FilterBuilders.termsFilter(key, values).execution(OR);
            } else if (queryNode.getValue().getOptionIds() != null && queryNode.getValue().getOptionIds().size() > 0) {
                return FilterBuilders.termsFilter(key, Str.UNDERSCORE_2X + queryNode.getValue().getOptionId() + Str.UNDERSCORE_2X);
            } else if (queryNode.getValue().getVal() != null) {
                if(queryNode.getValue().getAttribute().isAllowMultipleValues()){
                    key = ATT_PREFIX + Strings.slugify(queryNode.getValue().getAttribute().getCode()).replace(Char.MINUS, Char.UNDERSCORE) + RAW_SUFFIX;
                    return FilterBuilders.termsFilter(key, queryNode.getValue().getVal());
                } else {
                    key = ATT_PREFIX + Strings.slugify(queryNode.getValue().getAttribute().getCode()).replace(Char.MINUS, Char.UNDERSCORE) + RAW_SUFFIX;
                    return FilterBuilders.termFilter(key, queryNode.getValue().getVal());
                }
            } else {
                return FilterBuilders.missingFilter(key);
            }
        }
    }
    return null;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:43,代码来源:DefaultProductListHelper.java

示例9: buildQuery

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Override
public FilterBuilder buildQuery(QueryNode queryNode) {
    if (queryNode == null)
        return null;
    if (queryNode.getType().equals(QueryNodeType.BOOLEAN)) {
        List<FilterBuilder> filterBuilders = new ArrayList<>();
        if(queryNode.getNodes() != null) {
            for (QueryNode node : queryNode.getNodes()) {
                filterBuilders.add(buildQuery(node));
            }
            if (queryNode.getOperator().equals(AND)) {
                FilterBuilder andFilterBuilder = FilterBuilders.andFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
                return andFilterBuilder;
            } else {
                FilterBuilder orFilterBuilder = FilterBuilders.orFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
                return orFilterBuilder;
            }
        }
    } else {
        if (queryNode.getValue() != null && queryNode.getValue().getAttribute() != null) {
            String key = ATT_PREFIX + Strings.slugify(queryNode.getValue().getAttribute().getCode()).replace(Char.MINUS, Char.UNDERSCORE) + HASH_SUFFIX;
            if (queryNode.getValue().getOptionIds() != null && queryNode.getValue().getOptionIds().size() > 1) {
                List<String> values = new ArrayList<>();
                for (Id id : queryNode.getValue().getOptionIds()) {
                    values.add(Str.UNDERSCORE_2X + id + Str.UNDERSCORE_2X);
                }
                return FilterBuilders.termsFilter(key, values).execution(OR);
            } else if (queryNode.getValue().getOptionIds() != null && queryNode.getValue().getOptionIds().size() > 0) {
                return FilterBuilders.termsFilter(key, Str.UNDERSCORE_2X + queryNode.getValue().getOptionId() + Str.UNDERSCORE_2X);
            } else if (queryNode.getValue().getVal() != null) {
                if(queryNode.getValue().getAttribute().isAllowMultipleValues()){
                    key = ATT_PREFIX + Strings.slugify(queryNode.getValue().getAttribute().getCode()).replace(Char.MINUS, Char.UNDERSCORE) + RAW_SUFFIX;
                    return FilterBuilders.termsFilter(key, queryNode.getValue().getVal());
                } else {
                    if(StringUtils.isEmpty(queryNode.getComparator()) || "is".equals(queryNode.getComparator())){
                        key = ATT_PREFIX + Strings.slugify(queryNode.getValue().getAttribute().getCode()).replace(Char.MINUS, Char.UNDERSCORE) + RAW_SUFFIX;
                        return FilterBuilders.termFilter(key, queryNode.getValue().getVal());
                    } else {
                        key = ATT_PREFIX + Strings.slugify(queryNode.getValue().getAttribute().getCode()).replace(Char.MINUS, Char.UNDERSCORE) + RAW_SUFFIX;
                        if(queryNode.getComparator().equals("gt")){
                            return FilterBuilders.rangeFilter(key).gt(queryNode.getValue().getVal());
                        }
                        if(queryNode.getComparator().equals("gte")){
                            return FilterBuilders.rangeFilter(key).gte(queryNode.getValue().getVal());
                        }
                        if(queryNode.getComparator().equals("lt")){
                            return FilterBuilders.rangeFilter(key).lt(queryNode.getValue().getVal());
                        }
                        if(queryNode.getComparator().equals("lte")){
                            return FilterBuilders.rangeFilter(key).lte(queryNode.getValue().getVal());
                        }
                    }
                }
            } else {
                return FilterBuilders.missingFilter(key);
            }
        }
    }
    return null;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:61,代码来源:DefaultQueryHelper.java

示例10: getTermFilter

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private TermFilterBuilder getTermFilter(String fieldName, String fieldValue)
{
    return FilterBuilders.termFilter(fieldName, fieldValue);
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-tutorial,代码行数:5,代码来源:ProductQueryServiceImpl.java

示例11: getTermFilter

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private TermFilterBuilder getTermFilter(final String fieldName, final String fieldValue)
{
    return FilterBuilders.termFilter(fieldName, fieldValue);
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-akka,代码行数:5,代码来源:ProductQueryServiceImpl.java

示例12: getTermFilter

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private TermFilterBuilder getTermFilter(final String fieldName,
		final String fieldValue) {
	return FilterBuilders.termFilter(fieldName, fieldValue);
}
 
开发者ID:jaibeermalik,项目名称:searchanalytics-bigdata,代码行数:5,代码来源:ProductQueryServiceImpl.java

示例13: createFilterBuilder

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
/**
 * Create our filter builder.  We need to restrict our results on edge search, as well as on types, and any filters
 * that came from the grammar.
 */
private FilterBuilder createFilterBuilder( final SearchEdge searchEdge, final QueryVisitor visitor,
                                           final SearchTypes searchTypes ) {
    String context = createContextName( applicationScope, searchEdge );


    // Add our filter for context to our query for fast execution.
    // Fast because it utilizes bitsets internally. See this post for more detail.
    // http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/

    // TODO evaluate performance when it's an all query.
    // Do we need to put the context term first for performance?

    //make sure we have entity in the context
    BoolFilterBuilder boolQueryFilter = FilterBuilders.boolFilter();

    //add our edge search
    boolQueryFilter.must( FilterBuilders.termFilter( IndexingUtils.EDGE_SEARCH_FIELDNAME, context ) );


    /**
     * For the types the user specified, add them to an OR so 1 of them must match
     */
    final String[] sourceTypes = searchTypes.getTypeNames( applicationScope );


    if ( sourceTypes.length > 0 ) {
        final FilterBuilder[] typeTerms = new FilterBuilder[sourceTypes.length];

        for ( int i = 0; i < sourceTypes.length; i++ ) {
            typeTerms[i] = FilterBuilders.termFilter( IndexingUtils.ENTITY_TYPE_FIELDNAME, sourceTypes[i] );
        }

        //add all our types, 1 type must match per query
        boolQueryFilter.must( FilterBuilders.orFilter( typeTerms ) );
    }

    //if we have a filter from our visitor, add it

    Optional<FilterBuilder> queryBuilder = visitor.getFilterBuilder();

    if ( queryBuilder.isPresent() ) {
        boolQueryFilter.must( queryBuilder.get() );
    }

    return boolQueryFilter;
}
 
开发者ID:apache,项目名称:usergrid,代码行数:51,代码来源:SearchRequestBuilderStrategy.java

示例14: visit

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Override
public void visit( Equal op ) throws NoIndexException {
    final String name = op.getProperty().getValue().toLowerCase();
    final Object value = op.getLiteral().getValue();

    //special case so we support our '*' char with wildcard, also should work for uuids
    if ( value instanceof String || value instanceof UUID ) {
        String stringValue = ((value instanceof String) ? (String)value : value.toString()).toLowerCase().trim();

        // or field is just a string that does need a prefix us a query
        if ( stringValue.contains( "*" ) ) {

            //Because of our legacy behavior, where we match CCCC*, we need to use the unanalyzed string to ensure that
            //we start
            final WildcardQueryBuilder wildcardQuery =
                    QueryBuilders.wildcardQuery( IndexingUtils.FIELD_STRING_NESTED_UNANALYZED, stringValue );
            queryBuilders.push( fieldNameTerm( name, wildcardQuery ) );
            filterBuilders.push( NoOpFilterBuilder.INSTANCE );
            return;
        }

        // Usergrid query parser allows single quotes to be escaped in values
        if ( stringValue.contains("\\'")) {
            stringValue = stringValue.replace("\\'", "'");
        }

        //it's an exact match, use a filter
        final TermFilterBuilder termFilter =
                FilterBuilders.termFilter( IndexingUtils.FIELD_STRING_NESTED_UNANALYZED, stringValue );

        queryBuilders.push( NoOpQueryBuilder.INSTANCE );
        filterBuilders.push( fieldNameTerm( name, termFilter ) );

        return;
    }

    // assume all other types need prefix

    final TermFilterBuilder termQuery =
            FilterBuilders.termFilter(getFieldNameForType(value), sanitize(value));

    filterBuilders.push( fieldNameTerm( name, termQuery ) );

    queryBuilders.push( NoOpQueryBuilder.INSTANCE );
}
 
开发者ID:apache,项目名称:usergrid,代码行数:46,代码来源:EsQueryVistor.java

示例15: sortPropertyTermFilter

import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
/**
 * Create a term filter for our sorts
 */
public static TermFilterBuilder sortPropertyTermFilter( final String propertyName ) {
    return FilterBuilders.termFilter( IndexingUtils.FIELD_NAME, propertyName );
}
 
开发者ID:apache,项目名称:usergrid,代码行数:7,代码来源:SortBuilder.java


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