Java 类org.elasticsearch.index.query.TermFilterBuilder 实例源码

项目:elasticsearch-http    文件:IndicesAliasesActionHandlerTest.java   
@Test
public void should_create_alias_with_filter() throws Exception {
    String index = "index_without_alias";
    createIndex(index);
    ensureGreen(index);

    // add a mapping so I can add a filter, else it will fail due to strict resolution of fields
    createSimpleDoc(index, THE_TYPE, THE_ID);
    ensureSearchable(index);

    IndicesAliasesRequest request = new IndicesAliasesRequest();
    TermFilterBuilder filter = termFilter("the_string_field", "some_value");

    request.addAlias("the_alias", filter, index);
    IndicesAliasesResponse response = httpClient.admin().indices().aliases(request).get();

    Assertions.assertThat(response.isAcknowledged()).isTrue();

    GetAliasesResponse finalState = transportClient.admin().indices().getAliases(new GetAliasesRequest()).actionGet();
    Assertions.assertThat(finalState.getAliases().get(index)).hasSize(1);
    Assertions.assertThat(finalState.getAliases().get(index).get(0).alias()).isEqualTo("the_alias");

    String requestFilter = request.getAliasActions().get(0).aliasAction().filter();
    CompressedString actualFilter = finalState.getAliases().get(index).get(0).filter();
    Assertions.assertThat(actualFilter.string()).isEqualTo(requestFilter);
}
项目:portal-de-servicos    文件:ServicoRepository.java   
@Cacheable("servicos-por-area-de-interesse")
default List<ServicoXML> findByAreaDeInteresse(AreaDeInteresse areaDeInteresse) {
    return search(new NativeSearchQueryBuilder()
            .withFilter(new TermFilterBuilder("areasDeInteresse", singletonList(areaDeInteresse)))
            .withSort(new FieldSortBuilder("nome").order(ASC))
            .build())
            .getContent();
}
项目:portal-de-servicos    文件:ServicoRepository.java   
@Cacheable("servicos-por-segmento-da-sociedade")
default List<ServicoXML> findBySegmentoDaSociedade(SegmentoDaSociedade segmentoDaSociedade) {
    return search(new NativeSearchQueryBuilder()
            .withFilter(new TermFilterBuilder("segmentosDaSociedade", singletonList(segmentoDaSociedade)))
            .withSort(new FieldSortBuilder("nome").order(ASC))
            .build())
            .getContent();
}
项目:blackmarket    文件:ControlPane.java   
private FilterBuilder rarityOrFilter(List<Rarity> list) {
    List<TermFilterBuilder> filters = list.stream()
        .map(l -> termFilter("attributes.rarity", l.displayName()))
        .collect(Collectors.toList());
    TermFilterBuilder[] array = new TermFilterBuilder[filters.size()];
    array = filters.toArray(array); 
    return orFilter(array);
}
项目:elasticsearch-tutorial    文件:ProductQueryServiceImpl.java   
private TermFilterBuilder getTermFilter(String fieldName, String fieldValue)
{
    return FilterBuilders.termFilter(fieldName, fieldValue);
}
项目:elasticsearch-akka    文件:ProductQueryServiceImpl.java   
private TermFilterBuilder getTermFilter(final String fieldName, final String fieldValue)
{
    return FilterBuilders.termFilter(fieldName, fieldValue);
}
项目:searchanalytics-bigdata    文件:ProductQueryServiceImpl.java   
private TermFilterBuilder getTermFilter(final String fieldName,
        final String fieldValue) {
    return FilterBuilders.termFilter(fieldName, fieldValue);
}
项目:usergrid    文件:EsQueryVistor.java   
@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 );
}
项目:usergrid    文件:SortBuilder.java   
/**
 * Create a term filter for our sorts
 */
public static TermFilterBuilder sortPropertyTermFilter( final String propertyName ) {
    return FilterBuilders.termFilter( IndexingUtils.FIELD_NAME, propertyName );
}
项目:usergrid    文件:SearchRequestBuilderStrategy.java   
/**
 * Create a sort for the property name and field name specified
 *
 * @param sortOrder The sort order
 * @param fieldName The name of the field for the type
 * @param propertyName The property name the user specified for the sort
 */
private FieldSortBuilder createSort( final SortOrder sortOrder, final String fieldName,
                                     final String propertyName ) {

    final TermFilterBuilder propertyFilter = sortPropertyTermFilter( propertyName );


    return SortBuilders.fieldSort( fieldName ).order( sortOrder ).setNestedFilter( propertyFilter );
}
项目:usergrid    文件:EsQueryVistor.java   
@Override
public void visit( WithinOperand op ) {

    final String name = op.getProperty().getValue().toLowerCase();


    float lat = op.getLatitude().getFloatValue();
    float lon = op.getLongitude().getFloatValue();
    float distance = op.getDistance().getFloatValue();


    final FilterBuilder fb =
            FilterBuilders.geoDistanceFilter( IndexingUtils.FIELD_LOCATION_NESTED ).lat( lat ).lon( lon )
                          .distance( distance, DistanceUnit.METERS );


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


    //create our geo-sort based off of this point specified

    //this geoSort won't has a sort on it

    final GeoDistanceSortBuilder geoSort =
            SortBuilders.geoDistanceSort( IndexingUtils.FIELD_LOCATION_NESTED ).unit( DistanceUnit.METERS )
                        .geoDistance(GeoDistance.SLOPPY_ARC).point(lat, lon);

    final TermFilterBuilder sortPropertyName = sortPropertyTermFilter(name);

    geoSort.setNestedFilter( sortPropertyName );


    geoSortFields.addField(name, geoSort);
    //no op for query, push


    queryBuilders.push( NoOpQueryBuilder.INSTANCE );
}