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


Java RangeQueryBuilder类代码示例

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


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

示例1: createRangeQuery

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
private static RangeQueryBuilder createRangeQuery(String name, Map<String, Object> rangeOperation,
    Float boost) {

  RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(name+RAW_APPEND);
  for (Map.Entry<String, Object> it : rangeOperation.entrySet()) {
    if (it.getKey().equalsIgnoreCase(LTE)) {
      rangeQueryBuilder.lte(it.getValue());
    } else if (it.getKey().equalsIgnoreCase(LT)) {
      rangeQueryBuilder.lt(it.getValue());
    } else if (it.getKey().equalsIgnoreCase(GTE)) {
      rangeQueryBuilder.gte(it.getValue());
    } else if (it.getKey().equalsIgnoreCase(GT)) {
      rangeQueryBuilder.gt(it.getValue());
    }
  }
  if (isNotNull(boost)) {
    return rangeQueryBuilder.boost(boost);
  }
  return rangeQueryBuilder;
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:21,代码来源:ElasticSearchUtil.java

示例2: testUnsupportedQueries

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
public void testUnsupportedQueries() {
    RangeQueryBuilder rangeQuery1 = new RangeQueryBuilder("field").from("2016-01-01||/D").to("2017-01-01||/D");
    RangeQueryBuilder rangeQuery2 = new RangeQueryBuilder("field").from("2016-01-01||/D").to("now");
    PercolatorFieldMapper.verifyQuery(rangeQuery1);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(rangeQuery2));
    PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(rangeQuery1));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(rangeQuery2)));
    PercolatorFieldMapper.verifyQuery(new ConstantScoreQueryBuilder((rangeQuery1)));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new ConstantScoreQueryBuilder(rangeQuery2)));
    PercolatorFieldMapper.verifyQuery(new BoostingQueryBuilder(rangeQuery1, new MatchAllQueryBuilder()));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new BoostingQueryBuilder(rangeQuery2, new MatchAllQueryBuilder())));
    PercolatorFieldMapper.verifyQuery(new FunctionScoreQueryBuilder(rangeQuery1, new RandomScoreFunctionBuilder()));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new FunctionScoreQueryBuilder(rangeQuery2, new RandomScoreFunctionBuilder())));

    HasChildQueryBuilder hasChildQuery = new HasChildQueryBuilder("_type", new MatchAllQueryBuilder(), ScoreMode.None);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasChildQuery));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasChildQuery)));

    HasParentQueryBuilder hasParentQuery = new HasParentQueryBuilder("_type", new MatchAllQueryBuilder(), false);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasParentQuery));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasParentQuery)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:PercolatorFieldMapperTests.java

示例3: range

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
/**
 * @param operator operator <,>,<=,>=
 * @param field field name
 * @param stringValue field value
 * @return a range query
 */
static QueryBuilder range(String operator, String field, String stringValue) {
	String key = StringUtils.replaceAll(field, "[<>=\\s]+$", "");
	boolean nestedMode = nestedMode() && field.startsWith(PROPS_PREFIX);
	RangeQueryBuilder rfb = rangeQuery(nestedMode ? getValueFieldName(stringValue) : key);
	if (">".equals(operator)) {
		rfb.gt(getNumericValue(stringValue));
	} else if ("<".equals(operator)) {
		rfb.lt(getNumericValue(stringValue));
	} else if (">=".equals(operator)) {
		rfb.gte(getNumericValue(stringValue));
	} else if ("<=".equals(operator)) {
		rfb.lte(getNumericValue(stringValue));
	}
	if (nestedMode) {
		return nestedPropsQuery(keyValueBoolQuery(key, stringValue, rfb));
	} else {
		return rfb;
	}
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:26,代码来源:ElasticSearchUtils.java

示例4: termRange

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
private static QueryBuilder termRange(Query q) {
	QueryBuilder qb = null;
	TermRangeQuery trq = (TermRangeQuery) q;
	if (!StringUtils.isBlank(trq.getField())) {
		String from = trq.getLowerTerm() != null ? Term.toString(trq.getLowerTerm()) : "*";
		String to = trq.getUpperTerm() != null ? Term.toString(trq.getUpperTerm()) : "*";
		boolean nestedMode = nestedMode() && trq.getField().matches(PROPS_REGEX);
		qb = rangeQuery(nestedMode ? getValueFieldNameFromRange(from, to) : trq.getField());
		if ("*".equals(from) && "*".equals(to)) {
			qb = matchAllQuery();
		}
		if (!"*".equals(from)) {
			((RangeQueryBuilder) qb).from(getNumericValue(from)).includeLower(trq.includesLower());
		}
		if (!"*".equals(to)) {
			((RangeQueryBuilder) qb).to(getNumericValue(to)).includeUpper(trq.includesUpper());
		}
		if (nestedMode) {
			qb = nestedPropsQuery(keyValueBoolQuery(trq.getField(), qb));
		}
	}
	return qb;
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:24,代码来源:ElasticSearchUtils.java

示例5: setUp

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    doReturn(classValue).when(visitor).doGetPrimitiveFieldClass(any(PrimitiveStatement.class));

    doReturn(wildcardQueryBuilder).when(visitor).createWildcardQuery(anyString(), anyString());
    doReturn(boolQueryBuilder).when(visitor).createBoolQueryBuilder();
    doReturn(termQueryBuilder).when(visitor).createTermQuery(anyString(), any());
    doReturn(rangeQueryBuilder).when(visitor).createRangeQuery(anyString());

    doReturn(boolQueryBuilder).when(boolQueryBuilder).mustNot(any(QueryBuilder.class));
    doReturn(rangeQueryBuilder).when(rangeQueryBuilder).lt(any(RangeQueryBuilder.class));
    doReturn(rangeQueryBuilder).when(rangeQueryBuilder).lte(any(RangeQueryBuilder.class));
    doReturn(rangeQueryBuilder).when(rangeQueryBuilder).gt(any(RangeQueryBuilder.class));
    doReturn(rangeQueryBuilder).when(rangeQueryBuilder).gte(any(RangeQueryBuilder.class));

    // We'll test our enum-safe getter separately.
    doAnswer(answer -> answer.getArgumentAt(0, TestSearchConditionVisitor.ClassValue.class).getValue())
            .when(visitor).getEnumSafeValue(classValue);
}
 
开发者ID:8x8Cloud,项目名称:fiql-elasticsearch,代码行数:21,代码来源:ElasticsearchQueryBuilderVisitorTest.java

示例6: testBuildSimpleLessThanExpression

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
/**
 * Tests {@link ElasticsearchQueryBuilderVisitor#buildSimpleExpression(PrimitiveStatement)} for the case where
 * we're building a {@link ConditionType#LESS_THAN} expression.
 */
@SuppressWarnings("unchecked")
@Test
public void testBuildSimpleLessThanExpression() throws Exception {
    final Object value = "hello";
    final String property = "property";

    doReturn(value).when(classValue).getValue();
    doReturn(LESS_THAN).when(statement).getCondition();
    doReturn(property).when(statement).getProperty();

    assertThat(visitor.buildSimpleExpression(statement), instanceOf(RangeQueryBuilder.class));

    verify(visitor).buildSimpleExpression(statement);
    verify(visitor).doGetPrimitiveFieldClass(statement);
    verify(visitor).validateNotCollectionCheck(statement, classValue);
    verify(visitor).createRangeQuery(property);
    verify(visitor).getEnumSafeValue(classValue);

    verify(statement).getProperty();
    verify(statement).getCondition();

    verify(rangeQueryBuilder).lt(value);

    verifyNoMoreCollaboration();
}
 
开发者ID:8x8Cloud,项目名称:fiql-elasticsearch,代码行数:30,代码来源:ElasticsearchQueryBuilderVisitorTest.java

示例7: testBuildSimpleLessThanOrEqualsExpression

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
/**
 * Tests {@link ElasticsearchQueryBuilderVisitor#buildSimpleExpression(PrimitiveStatement)} for the case where
 * we're building a {@link ConditionType#LESS_OR_EQUALS} expression.
 */
@SuppressWarnings("unchecked")
@Test
public void testBuildSimpleLessThanOrEqualsExpression() throws Exception {
    final Object value = "hello";
    final String property = "property";

    doReturn(value).when(classValue).getValue();
    doReturn(LESS_OR_EQUALS).when(statement).getCondition();
    doReturn(property).when(statement).getProperty();

    assertThat(visitor.buildSimpleExpression(statement), instanceOf(RangeQueryBuilder.class));

    verify(visitor).buildSimpleExpression(statement);
    verify(visitor).doGetPrimitiveFieldClass(statement);
    verify(visitor).validateNotCollectionCheck(statement, classValue);
    verify(visitor).createRangeQuery(property);
    verify(visitor).getEnumSafeValue(classValue);

    verify(statement).getProperty();
    verify(statement).getCondition();

    verify(rangeQueryBuilder).lte(value);

    verifyNoMoreCollaboration();
}
 
开发者ID:8x8Cloud,项目名称:fiql-elasticsearch,代码行数:30,代码来源:ElasticsearchQueryBuilderVisitorTest.java

示例8: testBuildSimpleGreaterThanExpression

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
/**
 * Tests {@link ElasticsearchQueryBuilderVisitor#buildSimpleExpression(PrimitiveStatement)} for the case where
 * we're building a {@link ConditionType#GREATER_THAN} expression.
 */
@SuppressWarnings("unchecked")
@Test
public void testBuildSimpleGreaterThanExpression() throws Exception {
    final Object value = "hello";
    final String property = "property";

    doReturn(value).when(classValue).getValue();
    doReturn(GREATER_THAN).when(statement).getCondition();
    doReturn(property).when(statement).getProperty();

    assertThat(visitor.buildSimpleExpression(statement), instanceOf(RangeQueryBuilder.class));

    verify(visitor).buildSimpleExpression(statement);
    verify(visitor).doGetPrimitiveFieldClass(statement);
    verify(visitor).validateNotCollectionCheck(statement, classValue);
    verify(visitor).createRangeQuery(property);
    verify(visitor).getEnumSafeValue(classValue);

    verify(statement).getProperty();
    verify(statement).getCondition();

    verify(rangeQueryBuilder).gt(value);

    verifyNoMoreCollaboration();
}
 
开发者ID:8x8Cloud,项目名称:fiql-elasticsearch,代码行数:30,代码来源:ElasticsearchQueryBuilderVisitorTest.java

示例9: testBuildSimpleGreaterThanOrEqualsExpression

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
/**
 * Tests {@link ElasticsearchQueryBuilderVisitor#buildSimpleExpression(PrimitiveStatement)} for the case where
 * we're building a {@link ConditionType#GREATER_OR_EQUALS} expression.
 */
@SuppressWarnings("unchecked")
@Test
public void testBuildSimpleGreaterThanOrEqualsExpression() throws Exception {
    final Object value = "hello";
    final String property = "property";

    doReturn(value).when(classValue).getValue();
    doReturn(GREATER_OR_EQUALS).when(statement).getCondition();
    doReturn(property).when(statement).getProperty();

    assertThat(visitor.buildSimpleExpression(statement), instanceOf(RangeQueryBuilder.class));

    verify(visitor).buildSimpleExpression(statement);
    verify(visitor).doGetPrimitiveFieldClass(statement);
    verify(visitor).validateNotCollectionCheck(statement, classValue);
    verify(visitor).createRangeQuery(property);
    verify(visitor).getEnumSafeValue(classValue);

    verify(statement).getProperty();
    verify(statement).getCondition();

    verify(rangeQueryBuilder).gte(value);

    verifyNoMoreCollaboration();
}
 
开发者ID:8x8Cloud,项目名称:fiql-elasticsearch,代码行数:30,代码来源:ElasticsearchQueryBuilderVisitorTest.java

示例10: testMergeQueryPartsForLessThan

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
/**
 * Tests {@link ElasticsearchQueryBuilderVisitor#mergeQueryParts(QueryBuilder, QueryBuilder)} for the case where our
 * current query part is a less than/less than or equal to.
 */
@Test
public void testMergeQueryPartsForLessThan() throws Exception {
    final RangeQueryBuilder previousPart = mock(RangeQueryBuilder.class);
    final RangeQueryBuilder currentPart = mock(RangeQueryBuilder.class);
    final String toValue = "4000";
    final boolean includeUpper = true;

    doReturn(toValue).when(currentPart).to();
    doReturn(includeUpper).when(currentPart).includeUpper();

    visitor.mergeQueryParts(previousPart, currentPart);

    verify(visitor).mergeQueryParts(previousPart, currentPart);

    verify(previousPart).to(toValue);
    verify(previousPart).includeUpper(includeUpper);

    verify(currentPart, times(2)).to();
    verify(currentPart).includeUpper();

    verifyNoMoreCollaboration(previousPart, currentPart);
}
 
开发者ID:8x8Cloud,项目名称:fiql-elasticsearch,代码行数:27,代码来源:ElasticsearchQueryBuilderVisitorTest.java

示例11: testMergeQueryPartsForGreaterThan

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
/**
 * Tests {@link ElasticsearchQueryBuilderVisitor#mergeQueryParts(QueryBuilder, QueryBuilder)} for the case where our
 * current query part is a greater than/greater than or equal to.
 */
@Test
public void testMergeQueryPartsForGreaterThan() throws Exception {
    final RangeQueryBuilder previousPart = mock(RangeQueryBuilder.class);
    final RangeQueryBuilder currentPart = mock(RangeQueryBuilder.class);
    final String fromValue = "4000";
    final boolean includeLower = true;

    doReturn(fromValue).when(currentPart).from();
    doReturn(includeLower).when(currentPart).includeLower();

    visitor.mergeQueryParts(previousPart, currentPart);

    verify(visitor).mergeQueryParts(previousPart, currentPart);

    verify(previousPart).from(fromValue);
    verify(previousPart).includeLower(includeLower);

    verify(currentPart).to();
    verify(currentPart).from();
    verify(currentPart).includeLower();

    verifyNoMoreCollaboration(previousPart, currentPart);
}
 
开发者ID:8x8Cloud,项目名称:fiql-elasticsearch,代码行数:28,代码来源:ElasticsearchQueryBuilderVisitorTest.java

示例12: assertMultipleMetricAggregationWithScriptError

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
@Test
public void assertMultipleMetricAggregationWithScriptError() {
    String indexName = "test1";
    int size = 1;

    Map<String, Integer> termsFactor = new HashMap<String, Integer>();
    termsFactor.put("foo", 1);
    
    buildTestDataset(1, indexName, "type1", size, termsFactor);
    
    SearchResponse searchResponse = client().prepareSearch(indexName)
            .setQuery(matchAllQuery())
            .addAggregation(new MultipleMetricBuilder("metrics")
            		.script(new ScriptBuilder("ratio").script(new Script("value1 / value2")))
            		.field(new SumBuilder("value1").field("value1"))
            		.field(new CountBuilder("value2").field("value2").filter(new RangeQueryBuilder("value1").gt(1000))))
            .execute().actionGet();
    
    MultipleMetric metrics = searchResponse.getAggregations().get("metrics");
    assertEquals(metrics.getValue("value1"), 45.0 * size, 0.0);
    assertEquals(metrics.getValue("value2"), 0.0 * size, 0.0);
    assertEquals(metrics.getValue("ratio"), Double.POSITIVE_INFINITY, 0.0);
    
    assertEquals(metrics.getDocCount("value1"), 10);
    assertEquals(metrics.getDocCount("value2"), 0);
}
 
开发者ID:eliep,项目名称:elasticsearch-multiple-metric-aggregation,代码行数:27,代码来源:MultipleMetricAggregatorTest.java

示例13: assertMultipleMetricAggregationWithFilter

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
@Test
public void assertMultipleMetricAggregationWithFilter() {
    String indexName = "test2";
    int size = 1;

    Map<String, Integer> termsFactor = new HashMap<String, Integer>();
    termsFactor.put("foo", 1);
    
    buildTestDataset(1, indexName, "type1", size, termsFactor);
    
    SearchResponse searchResponse = client().prepareSearch(indexName)
            .setQuery(matchAllQuery())
            .addAggregation(new MultipleMetricBuilder("metrics")
            		.script(new ScriptBuilder("ratio").script(new Script("value1 / value2")))
            		.field(new SumBuilder("value1").field("value1").filter(new RangeQueryBuilder("value1").gt(5)))
            		.field(new CountBuilder("value2").field("value2")))
            .execute().actionGet();
    
    MultipleMetric metrics = searchResponse.getAggregations().get("metrics");
    assertEquals(metrics.getValue("value1"), 30.0 * size, 0.0);
    assertEquals(metrics.getValue("value2"), 10.0 * size, 0.0);
    assertEquals(metrics.getValue("ratio"), metrics.getValue("value1") / metrics.getValue("value2"), 0.0);
    
    assertEquals(metrics.getDocCount("value1"), 4);
    assertEquals(metrics.getDocCount("value2"), 10);
}
 
开发者ID:eliep,项目名称:elasticsearch-multiple-metric-aggregation,代码行数:27,代码来源:MultipleMetricAggregatorTest.java

示例14: assertMultipleMetricAggregationWithUnmappedField

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
@Test
public void assertMultipleMetricAggregationWithUnmappedField() {
    String indexName = "test3";
    int size = 1;

    Map<String, Integer> termsFactor = new HashMap<String, Integer>();
    termsFactor.put("foo", 1);
    
    buildTestDataset(1, indexName, "type1", size, termsFactor);
    
    SearchResponse searchResponse = client().prepareSearch(indexName)
            .setQuery(matchAllQuery())
            .addAggregation(new MultipleMetricBuilder("metrics")
            		.script(new ScriptBuilder("ratio").script(new Script("value1 + value2")))
            		.field(new SumBuilder("value1").field("value4").filter(new RangeQueryBuilder("value1").gt(5)))
            		.field(new CountBuilder("value2").field("value5")))
            .execute().actionGet();
    
    MultipleMetric metrics = searchResponse.getAggregations().get("metrics");
    assertEquals(metrics.getValue("value1"), 0.0, 0.0);
    assertEquals(metrics.getValue("value2"), 0.0, 0.0);
    assertEquals(metrics.getValue("ratio"), metrics.getValue("value1") + metrics.getValue("value2"), 0.0);
    
    assertEquals(metrics.getDocCount("value1"), 0);
    assertEquals(metrics.getDocCount("value2"), 0);
}
 
开发者ID:eliep,项目名称:elasticsearch-multiple-metric-aggregation,代码行数:27,代码来源:MultipleMetricAggregatorTest.java

示例15: adaptRequestBuilder

import org.elasticsearch.index.query.RangeQueryBuilder; //导入依赖的package包/类
@Override
protected SearchRequestBuilder adaptRequestBuilder(final Client esClient,
		final SearchRequestBuilder requestBuilder) {
	QueryBuilder filter = null;
	if (from != null || to != null) {
		final RangeQueryBuilder occRange = QueryBuilders.rangeQuery(Event.FIELD_TIMESTAMP);
		if (from != null) {
			occRange.gte(from.getTime());
		}
		if (to != null) {
			occRange.lte(to.getTime());
		}
		filter = occRange;
	}
	if (filter != null) {
		requestBuilder.setQuery(filter);
	}
	return requestBuilder;
}
 
开发者ID:logsniffer,项目名称:logsniffer,代码行数:20,代码来源:EsEventPersistence.java


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