本文整理汇总了Java中org.elasticsearch.index.query.RangeFilterBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RangeFilterBuilder类的具体用法?Java RangeFilterBuilder怎么用?Java RangeFilterBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RangeFilterBuilder类属于org.elasticsearch.index.query包,在下文中一共展示了RangeFilterBuilder类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rangeFilter
import org.elasticsearch.index.query.RangeFilterBuilder; //导入依赖的package包/类
public FilterBuilder rangeFilter(String name) {
FilterBuilder filter = null;
if(max.isPresent() && max.get() == 0) {
filter = FilterBuilders.notFilter(FilterBuilders.existsFilter(name));
} else {
RangeFilterBuilder rfilter = FilterBuilders.rangeFilter(name);
min.ifPresent(m -> rfilter.from(m));
max.ifPresent(m -> rfilter.to(m));
filter = rfilter;
}
return filter;
}
示例2: convert
import org.elasticsearch.index.query.RangeFilterBuilder; //导入依赖的package包/类
@Override
public FilterBuilder convert(Filter filter) {
boolean cache = filter.getBoolean("cache", false);
String field = filter.getString("field");
if (field == null) {
field = filter.getName();
}
RangeFilterBuilder result = rangeFilter(field).cache(cache);
String gte = filter.getString("gte");
String gt = filter.getString("gt");
String lt = filter.getString("lt");
String lte = filter.getString("lte");
String time_zone = filter.getString("time_zone");
if (gte != null) {
result.gte(gte);
}
if (gt != null) {
result.gt(gt);
}
if (lt != null) {
result.lt(lt);
}
if (lte != null) {
result.lte(lte);
}
if (time_zone != null) {
result.timeZone(time_zone);
}
return result;
}
示例3: dateRangeFilter
import org.elasticsearch.index.query.RangeFilterBuilder; //导入依赖的package包/类
public FilterBuilder dateRangeFilter(ReadableInstant from, ReadableInstant to) {
if (from == null && to == null) {
return matchAllFilter();
}
RangeFilterBuilder dateFilter = rangeFilter("commit.commitdate");
if (from != null) {
dateFilter.gte(from.getMillis());
}
if (to != null) {
dateFilter.lte(to.getMillis());
}
// Match all files as well, since they don't have date info (user can turn off by
// unchecking "search files" option.)
return orFilter(dateFilter, typeFilter("file"));
}
示例4: buildSingleRangeFilter
import org.elasticsearch.index.query.RangeFilterBuilder; //导入依赖的package包/类
private FilterBuilder buildSingleRangeFilter(String key, String value) {
String[] values = value.split(" - ");
if (value.length() == 0) {
return null;
}
RangeFilterBuilder filterBuilder = FilterBuilders.rangeFilter(key);
if (value.length() == 2) {
filterBuilder.from(Double.valueOf(values[0]).doubleValue()).to(Double.valueOf(values[1]));
} else if (value.startsWith(values[0])) {
filterBuilder.gte(Double.valueOf(values[0]).doubleValue());
} else {
filterBuilder.lt(Double.valueOf(values[0]).doubleValue());
}
return filterBuilder;
}
示例5: scan
import org.elasticsearch.index.query.RangeFilterBuilder; //导入依赖的package包/类
/**
* Perform a range scan for a set of records in the database. Each
* field/value pair from the result will be stored in a HashMap.
*
* @param table The name of the table
* @param startkey The record key of the first record to read.
* @param recordcount The number of records to read
* @param fields The list of fields to read, or null for all of them
* @param result A Vector of HashMaps, where each HashMap is a set
* field/value pairs for one record
* @return Zero on success, a non-zero error code on error. See this class's
* description for a discussion of error codes.
*/
@Override
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
final RangeFilterBuilder filter = rangeFilter("_id").gte(startkey);
final SearchResponse response = client.prepareSearch(indexKey)
.setTypes(table)
.setQuery(matchAllQuery())
.setFilter(filter)
.setSize(recordcount)
.execute()
.actionGet();
HashMap<String, ByteIterator> entry;
for (SearchHit hit : response.getHits()) {
entry = new HashMap<String, ByteIterator>(fields.size());
for (String field : fields) {
entry.put(field, new StringByteIterator((String) hit.getSource().get(field)));
}
result.add(entry);
}
return 0;
} catch (Exception e) {
e.printStackTrace();
}
return 1;
}
示例6: buildQuery
import org.elasticsearch.index.query.RangeFilterBuilder; //导入依赖的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
示例7: visit
import org.elasticsearch.index.query.RangeFilterBuilder; //导入依赖的package包/类
@Override
public void visit( LessThan op ) throws NoIndexException {
final String name = op.getProperty().getValue().toLowerCase();
final Object value = op.getLiteral().getValue();
final RangeFilterBuilder termQuery =
FilterBuilders.rangeFilter( getFieldNameForType( value ) ).lt(sanitize(value));
queryBuilders.push( NoOpQueryBuilder.INSTANCE );
//we do this by query, push empty
filterBuilders.push( fieldNameTerm( name, termQuery ) );
}
示例8: withRangeFilter
import org.elasticsearch.index.query.RangeFilterBuilder; //导入依赖的package包/类
/**
* Allows you to add and configure a range filter for the specified propertyName
* @param propertyName
* @return
*/
RangeFilterBuilder withRangeFilter(String propertyName);