本文整理汇总了Java中org.elasticsearch.index.query.FilterBuilders.andFilter方法的典型用法代码示例。如果您正苦于以下问题:Java FilterBuilders.andFilter方法的具体用法?Java FilterBuilders.andFilter怎么用?Java FilterBuilders.andFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.index.query.FilterBuilders
的用法示例。
在下文中一共展示了FilterBuilders.andFilter方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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()]));
}
示例2: 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());
}
}
示例3: 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());
// }
}
示例4: getFilterBuilder
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Override
public FilterBuilder getFilterBuilder() {
List<FilterBuilder> filterBuilders = new ArrayList<>();
if (this.getPriceFrom() != null || this.getPriceTo() != null) {
filterBuilders.add(FilterBuilders.rangeFilter("price").from(this.getPriceFrom()).to(this.getPriceTo()));
}
return filterBuilders.size() == 0 ? null
: FilterBuilders.andFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
}
示例5: addFacetFilter
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private static void addFacetFilter(FacetBuilder facet, String filterJson, FilterBuilder visibilityFilter) {
// If filterJson is set add it along with visibility filter
final FilterBuilder facetFilter;
if (StringUtils.isBlank(filterJson)) {
facetFilter = visibilityFilter;
} else {
facetFilter = FilterBuilders.andFilter(FilterBuilders.wrapperFilter(filterJson), visibilityFilter);
facet.facetFilter(FilterBuilders.wrapperFilter(filterJson));
}
facet.facetFilter(facetFilter);
}
示例6: getAndFilter
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private FilterBuilder getAndFilter(List<FilterBuilder> filters) {
if (filters.size() == 1) {
return filters.get(0);
}
return FilterBuilders.andFilter(filters.toArray(new FilterBuilder[filters.size()]));
}
示例7: 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
示例8: buildQuery
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Override
public QueryBuilder buildQuery(List<FilterBuilder> builders, Map<String, FilterValue> filterParams) {
List<FilterBuilder> filterBuilders = new ArrayList<>();
if(filterParams != null) {
for (String key : filterParams.keySet()) {
FilterValue filterValue = filterParams.get(key);
FilterType filterType = filterValue.getFilterType();
Set<Object> value = filterValue.getValues();
if (filterType == FilterType.RANGE) {
RangeFilterBuilder rangeFilterBuilder = FilterBuilders.rangeFilter(key);
Object[] values = value.toArray();
if (value.size() > 1) {
rangeFilterBuilder.from(Double.parseDouble((String) values[0]));
rangeFilterBuilder.to(Double.parseDouble((String) values[1]));
} else if (value.size() > 0) {
rangeFilterBuilder.from(Double.parseDouble((String) values[0]));
} else {
rangeFilterBuilder.from(0);
}
filterBuilders.add(rangeFilterBuilder);
} else {
if (value.size() > 1) {
filterBuilders.add(FilterBuilders.termsFilter(key, value.toArray()).execution("or"));
} else if (value.size() > 0) {
filterBuilders.add(FilterBuilders.termsFilter(key, value.iterator().next()));
}
}
}
}
if (builders != null && !builders.isEmpty())
filterBuilders.addAll(builders);
if(filterBuilders.size() > 1){
FilterBuilder andFilterBuilder = FilterBuilders
.andFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
return QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), andFilterBuilder);
} else {
return QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filterBuilders.get(0));
}
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:50,代码来源:DefaultElasticsearchHelper.java
示例9: getFilterBuilder
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
public FilterBuilder getFilterBuilder() {
List<FilterBuilder> filterBuilders = new ArrayList<>();
return filterBuilders.size() == 0 ? null
: FilterBuilders.andFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
}
示例10: 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;
}
示例11: getSpecificationsFacetFilterBuilder
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private FilterBuilder getSpecificationsFacetFilterBuilder(SearchCriteria searchCriteria)
{
//This is used in case you want to search based on separate resolution/memory facets
Map<String, List<String>> multiSelectFilters = searchCriteria.getMultiSelectFilters();
List<String> resolutionFilters = new ArrayList<String>();
List<String> memoryFilters = new ArrayList<String>();
for (Entry<String, List<String>> entry : multiSelectFilters.entrySet())
{
if(entry.getKey().equals(SearchFacetName.SPECIFICATION_RESOLUTION.getCode()))
{
resolutionFilters.addAll(entry.getValue());
}
else if(entry.getKey().equals(SearchFacetName.SPECIFICATION_MEMORY.getCode()))
{
memoryFilters.addAll(entry.getValue());
}
}
if(resolutionFilters.size() == 0 && memoryFilters.size() == 0 )
{
return FilterBuilders.queryFilter(QueryBuilders.matchAllQuery());
}
AndFilterBuilder andResolutionAndMemoryFilterBuilder = FilterBuilders.andFilter();
if(resolutionFilters.size() > 0)
{
OrFilterBuilder OrResolutionFilterBuilder = FilterBuilders.orFilter();
for (String resolution : resolutionFilters)
{
OrResolutionFilterBuilder.add(FilterBuilders.termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), resolution));
}
andResolutionAndMemoryFilterBuilder.add(OrResolutionFilterBuilder);
}
if(memoryFilters.size() > 0)
{
OrFilterBuilder OrMemoryFilterBuilder = FilterBuilders.orFilter();
for (String memory : memoryFilters)
{
OrMemoryFilterBuilder.add(FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), memory));
}
andResolutionAndMemoryFilterBuilder.add(OrMemoryFilterBuilder);
}
// else if(specifications.size() == 1)
// {
// Specification specification = searchCriteria.getSpecifications().get(0);
//
// FilterBuilder filterBuilder = FilterBuilders.andFilter(FilterBuilders
// .termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), specification.getResolution()),
// FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), specification.getMemory()));
//
// specificationFilterBuilder = filterBuilder;
// }
// else
// {
// specificationFilterBuilder = FilterBuilders.matchAllFilter();
// }
return andResolutionAndMemoryFilterBuilder;
}
示例12: getSpecificationsFacetFilterBuilder
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private FilterBuilder getSpecificationsFacetFilterBuilder(final SearchCriteria searchCriteria)
{
// This is used in case you want to search based on separate resolution/memory facets
final Map<String, List<String>> multiSelectFilters = searchCriteria.getMultiSelectFilters();
final List<String> resolutionFilters = new ArrayList<String>();
final List<String> memoryFilters = new ArrayList<String>();
for (final Entry<String, List<String>> entry : multiSelectFilters.entrySet())
{
if (entry.getKey().equals(SearchFacetName.SPECIFICATION_RESOLUTION.getCode()))
{
resolutionFilters.addAll(entry.getValue());
}
else if (entry.getKey().equals(SearchFacetName.SPECIFICATION_MEMORY.getCode()))
{
memoryFilters.addAll(entry.getValue());
}
}
if (resolutionFilters.size() == 0 && memoryFilters.size() == 0)
{
return FilterBuilders.queryFilter(QueryBuilders.matchAllQuery());
}
final AndFilterBuilder andResolutionAndMemoryFilterBuilder = FilterBuilders.andFilter();
if (resolutionFilters.size() > 0)
{
final OrFilterBuilder OrResolutionFilterBuilder = FilterBuilders.orFilter();
for (final String resolution : resolutionFilters)
{
OrResolutionFilterBuilder.add(FilterBuilders.termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), resolution));
}
andResolutionAndMemoryFilterBuilder.add(OrResolutionFilterBuilder);
}
if (memoryFilters.size() > 0)
{
final OrFilterBuilder OrMemoryFilterBuilder = FilterBuilders.orFilter();
for (final String memory : memoryFilters)
{
OrMemoryFilterBuilder.add(FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), memory));
}
andResolutionAndMemoryFilterBuilder.add(OrMemoryFilterBuilder);
}
// else if(specifications.size() == 1)
// {
// Specification specification = searchCriteria.getSpecifications().get(0);
//
// FilterBuilder filterBuilder = FilterBuilders.andFilter(FilterBuilders
// .termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), specification.getResolution()),
// FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), specification.getMemory()));
//
// specificationFilterBuilder = filterBuilder;
// }
// else
// {
// specificationFilterBuilder = FilterBuilders.matchAllFilter();
// }
return andResolutionAndMemoryFilterBuilder;
}
示例13: getSpecificationsFacetFilterBuilder
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private FilterBuilder getSpecificationsFacetFilterBuilder(
final SearchCriteria searchCriteria) {
// This is used in case you want to search based on separate
// resolution/memory facets
final Map<String, List<String>> multiSelectFilters = searchCriteria
.getMultiSelectFilters();
final List<String> resolutionFilters = new ArrayList<String>();
final List<String> memoryFilters = new ArrayList<String>();
for (final Entry<String, List<String>> entry : multiSelectFilters
.entrySet()) {
if (entry.getKey().equals(
SearchFacetName.SPECIFICATION_RESOLUTION.getCode())) {
resolutionFilters.addAll(entry.getValue());
} else if (entry.getKey().equals(
SearchFacetName.SPECIFICATION_MEMORY.getCode())) {
memoryFilters.addAll(entry.getValue());
}
}
if (resolutionFilters.size() == 0 && memoryFilters.size() == 0) {
return FilterBuilders.queryFilter(QueryBuilders.matchAllQuery());
}
final AndFilterBuilder andResolutionAndMemoryFilterBuilder = FilterBuilders
.andFilter();
if (resolutionFilters.size() > 0) {
final OrFilterBuilder OrResolutionFilterBuilder = FilterBuilders
.orFilter();
for (final String resolution : resolutionFilters) {
OrResolutionFilterBuilder.add(FilterBuilders.termFilter(
SearchDocumentFieldName.RESOLUTION.getFieldName(),
resolution));
}
andResolutionAndMemoryFilterBuilder.add(OrResolutionFilterBuilder);
}
if (memoryFilters.size() > 0) {
final OrFilterBuilder OrMemoryFilterBuilder = FilterBuilders
.orFilter();
for (final String memory : memoryFilters) {
OrMemoryFilterBuilder.add(FilterBuilders.termFilter(
SearchDocumentFieldName.MEMORY.getFieldName(), memory));
}
andResolutionAndMemoryFilterBuilder.add(OrMemoryFilterBuilder);
}
// else if(specifications.size() == 1)
// {
// Specification specification =
// searchCriteria.getSpecifications().get(0);
//
// FilterBuilder filterBuilder = FilterBuilders.andFilter(FilterBuilders
// .termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(),
// specification.getResolution()),
// FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(),
// specification.getMemory()));
//
// specificationFilterBuilder = filterBuilder;
// }
// else
// {
// specificationFilterBuilder = FilterBuilders.matchAllFilter();
// }
return andResolutionAndMemoryFilterBuilder;
}