• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TermQueryBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testSimpleDiversity

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testSimpleDiversity() throws Exception {
    int MAX_DOCS_PER_AUTHOR = 1;
    DiversifiedAggregationBuilder sampleAgg = new DiversifiedAggregationBuilder("sample").shardSize(100);
    sampleAgg.field("author").maxDocsPerValue(MAX_DOCS_PER_AUTHOR).executionHint(randomExecutionHint());
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("genre", "fantasy"))
            .setFrom(0).setSize(60)
            .addAggregation(sampleAgg)
            .execute()
            .actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    Terms authors = sample.getAggregations().get("authors");
    Collection<Bucket> testBuckets = authors.getBuckets();

    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket.getDocCount(), lessThanOrEqualTo((long) NUM_SHARDS * MAX_DOCS_PER_AUTHOR));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DiversifiedSamplerIT.java


示例2: testSimpleSampler

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testSimpleSampler() throws Exception {
    SamplerAggregationBuilder sampleAgg = sampler("sample").shardSize(100);
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("test").setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("genre", "fantasy")).setFrom(0).setSize(60).addAggregation(sampleAgg).execute().actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    Terms authors = sample.getAggregations().get("authors");
    Collection<Bucket> testBuckets = authors.getBuckets();

    long maxBooksPerAuthor = 0;
    for (Terms.Bucket testBucket : testBuckets) {
        maxBooksPerAuthor = Math.max(testBucket.getDocCount(), maxBooksPerAuthor);
    }
    assertThat(maxBooksPerAuthor, equalTo(3L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SamplerIT.java


示例3: testUnmappedChildAggNoDiversity

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testUnmappedChildAggNoDiversity() throws Exception {
    SamplerAggregationBuilder sampleAgg = sampler("sample").shardSize(100);
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("idx_unmapped")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("genre", "fantasy"))
            .setFrom(0).setSize(60)
            .addAggregation(sampleAgg)
            .execute()
            .actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    assertThat(sample.getDocCount(), equalTo(0L));
    Terms authors = sample.getAggregations().get("authors");
    assertThat(authors.getBuckets().size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SamplerIT.java


示例4: testPartiallyUnmappedChildAggNoDiversity

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testPartiallyUnmappedChildAggNoDiversity() throws Exception {
    SamplerAggregationBuilder sampleAgg = sampler("sample").shardSize(100);
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("idx_unmapped", "test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("genre", "fantasy"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(sampleAgg)
            .execute()
            .actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    assertThat(sample.getDocCount(), greaterThan(0L));
    Terms authors = sample.getAggregations().get("authors");
    assertThat(authors.getBuckets().size(), greaterThan(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SamplerIT.java


示例5: testFilteredAnalysis

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testFilteredAnalysis() throws Exception {
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "weller"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms").field("description")
                       .minDocCount(1).backgroundFilter(QueryBuilders.termsQuery("description",  "paul")))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    HashSet<String> topWords = new HashSet<String>();
    for (Bucket topTerm : topTerms) {
        topWords.add(topTerm.getKeyAsString());
    }
    //The word "paul" should be a constant of all docs in the background set and therefore not seen as significant
    assertFalse(topWords.contains("paul"));
    //"Weller" is the only Paul who was in The Jam and therefore this should be identified as a differentiator from the background of all other Pauls.
    assertTrue(topWords.contains("jam"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SignificantTermsIT.java


示例6: testDefaultSignificanceHeuristic

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testDefaultSignificanceHeuristic() throws Exception {
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "terje"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms")
                    .field("description")
                    .executionHint(randomExecutionHint())
                    .significanceHeuristic(new JLHScore())
                    .minDocCount(2))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    checkExpectedStringTermsFound(topTerms);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SignificantTermsIT.java


示例7: testMutualInformation

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testMutualInformation() throws Exception {
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "terje"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms")
                    .field("description")
                    .executionHint(randomExecutionHint())
                    .significanceHeuristic(new MutualInformation(false, true))
                    .minDocCount(1))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    checkExpectedStringTermsFound(topTerms);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SignificantTermsIT.java


示例8: testBuildSimpleEqualsExpression

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

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

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

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

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

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


示例9: countReplies

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
@Override
public long countReplies(String id) {

    // Prepare count request
    SearchRequestBuilder searchRequest = client
            .prepareSearch(getIndex())
            .setTypes(getType())
            .setFetchSource(false)
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setSize(0);

    // Query = filter on reference
    TermQueryBuilder query = QueryBuilders.termQuery(RecordComment.PROPERTY_REPLY_TO_JSON, id);
    searchRequest.setQuery(query);

    // Execute query
    try {
        SearchResponse response = searchRequest.execute().actionGet();
        return response.getHits().getTotalHits();
    }
    catch(SearchPhaseExecutionException e) {
        // Failed or no item on index
        logger.error(String.format("Error while counting comment replies: %s", e.getMessage()), e);
    }
    return 1;
}
 
开发者ID:duniter-gchange,项目名称:gchange-pod,代码行数:27,代码来源:AbstractCommentDaoImpl.java


示例10: getDriver

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
private Driver getDriver(Credentials credentials) {
	TermQueryBuilder query = QueryBuilders.termQuery("credentialsId", credentials.id());

	SearchResponse response = Start.get().getElasticClient()//
			.prepareSearch(credentials.backendId(), "driver")//
			.setQuery(query)//
			.setSize(1)//
			.get();

	if (response.getHits().getTotalHits() != 1)
		throw Exceptions.illegalArgument("credentials [%s] has more than one driver", credentials.name());

	SearchHit hit = response.getHits().getHits()[0];
	Driver driver = Json7.toPojo(hit.sourceAsString(), Driver.class);
	driver.id = hit.id();
	return driver;
}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:18,代码来源:CaremenResource.java


示例11: runTest

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
void runTest() {
		System.out.println("Running");
		IResult r = null;

	//	StringBuilder buf = new StringBuilder();
	//		buf.append("{\"from\":"+0+",\"size\":"+30+",");
		//fails {"size":30, "from":0,"term": {"sbOf": "TypeType"}}
		//fails {"from":0, "size":30,"query":{"term": {"sbOf": "TypeType"}}}
		//fails: {"from":0,"size":30,"query":{"term":{"sbOf":"TypeType"}}}
		//fails: {"from":0,"size":30,"query":{"match":{"sbOf":"TypeType"}}}
		//http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-from-size.html
		TermQueryBuilder termQuery = QueryBuilders.termQuery(ITopicQuestsOntology.SUBCLASS_OF_PROPERTY_TYPE, ITopicQuestsOntology.TYPE_TYPE);
		//StringBuilder buf1 = new StringBuilder("\"query\":{\"term\":{");
//		StringBuilder buf1 = new StringBuilder("\"term\": {");
		//buf1.append("\""+ITopicQuestsOntology.SUBCLASS_OF_PROPERTY_TYPE+"\":\""+ITopicQuestsOntology.TYPE_TYPE+"\"}}}");
//		buf1.append("\""+ITopicQuestsOntology.SUBCLASS_OF_PROPERTY_TYPE+"\": \""+ITopicQuestsOntology.TYPE_TYPE+"\"}}");
//		buf.append(termQuery.toString());
//		StringBuilder buf = new StringBuilder("{\"term\":{");
//		buf.append("\""+ITopicQuestsOntology.SUBCLASS_OF_PROPERTY_TYPE+"\": \""+ITopicQuestsOntology.TYPE_TYPE+"\"},");
//		buf.append("\"from\":"+10+",\"size\":"+30+"}");
		r = database.runQuery(termQuery.toString(), 3, 2, credentials);
		System.out.println("Done "+r.getErrorString()+" "+r.getResultObject());
		environment.shutDown();
	}
 
开发者ID:SolrSherlock,项目名称:JSONTopicMap,代码行数:25,代码来源:QueryTest2.java


示例12: testRewriteWithInnerBoost

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testRewriteWithInnerBoost() throws IOException {
    final TermQueryBuilder query = new TermQueryBuilder("foo", "bar").boost(2);
    QueryBuilder builder = new TemplateQueryBuilder(new Script(ScriptType.INLINE, "mockscript", query.toString(),
        Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()), Collections.emptyMap()));
    assertEquals(query, builder.rewrite(createShardContext()));

    builder = new TemplateQueryBuilder(new Script(ScriptType.INLINE, "mockscript", query.toString(),
        Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()), Collections.emptyMap())).boost(3);
    assertEquals(new BoolQueryBuilder().must(query).boost(3), builder.rewrite(createShardContext()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:TemplateQueryBuilderTests.java


示例13: testPartiallyUnmappedDiversifyField

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testPartiallyUnmappedDiversifyField() throws Exception {
    // One of the indexes is missing the "author" field used for
    // diversifying results
    DiversifiedAggregationBuilder sampleAgg = new DiversifiedAggregationBuilder("sample").shardSize(100).field("author")
            .maxDocsPerValue(1);
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("idx_unmapped_author", "test").setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("genre", "fantasy")).setFrom(0).setSize(60).addAggregation(sampleAgg)
            .execute().actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    assertThat(sample.getDocCount(), greaterThan(0L));
    Terms authors = sample.getAggregations().get("authors");
    assertThat(authors.getBuckets().size(), greaterThan(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:DiversifiedSamplerIT.java


示例14: testWhollyUnmappedDiversifyField

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testWhollyUnmappedDiversifyField() throws Exception {
    //All of the indices are missing the "author" field used for diversifying results
    int MAX_DOCS_PER_AUTHOR = 1;
    DiversifiedAggregationBuilder sampleAgg = new DiversifiedAggregationBuilder("sample").shardSize(100);
    sampleAgg.field("author").maxDocsPerValue(MAX_DOCS_PER_AUTHOR).executionHint(randomExecutionHint());
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("idx_unmapped", "idx_unmapped_author").setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("genre", "fantasy")).setFrom(0).setSize(60).addAggregation(sampleAgg).execute().actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    assertThat(sample.getDocCount(), equalTo(0L));
    Terms authors = sample.getAggregations().get("authors");
    assertNull(authors);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:DiversifiedSamplerIT.java


示例15: testStructuredAnalysis

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testStructuredAnalysis() throws Exception {
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "terje"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms").field("fact_category").executionHint(randomExecutionHint())
                       .minDocCount(2))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    Number topCategory = (Number) topTerms.getBuckets().iterator().next().getKey();
    assertTrue(topCategory.equals(Long.valueOf(SNOWBOARDING_CATEGORY)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:SignificantTermsIT.java


示例16: testStructuredAnalysisWithIncludeExclude

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testStructuredAnalysisWithIncludeExclude() throws Exception {
    long[] excludeTerms = { MUSIC_CATEGORY };
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "paul"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms").field("fact_category").executionHint(randomExecutionHint())
                       .minDocCount(1).includeExclude(new IncludeExclude(null, excludeTerms)))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    Number topCategory = (Number) topTerms.getBuckets().iterator().next().getKey();
    assertTrue(topCategory.equals(Long.valueOf(OTHER_CATEGORY)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:SignificantTermsIT.java


示例17: testUnmapped

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx_unmapped")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "terje"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms").field("fact_category").executionHint(randomExecutionHint())
                    .minDocCount(2))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    assertThat(topTerms.getBuckets().size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SignificantTermsIT.java


示例18: testTextAnalysis

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testTextAnalysis() throws Exception {
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "terje"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms").field("description").executionHint(randomExecutionHint())
                       .minDocCount(2))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    checkExpectedStringTermsFound(topTerms);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SignificantTermsIT.java


示例19: testTextAnalysisGND

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testTextAnalysisGND() throws Exception {
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "terje"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms").field("description").executionHint(randomExecutionHint()).significanceHeuristic(new GND(true))
                    .minDocCount(2))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    checkExpectedStringTermsFound(topTerms);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SignificantTermsIT.java


示例20: testTextAnalysisChiSquare

import org.elasticsearch.index.query.TermQueryBuilder; //导入依赖的package包/类
public void testTextAnalysisChiSquare() throws Exception {
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("description", "terje"))
            .setFrom(0).setSize(60).setExplain(true)
            .addAggregation(significantTerms("mySignificantTerms").field("description").executionHint(randomExecutionHint()).significanceHeuristic(new ChiSquare(false,true))
                    .minDocCount(2))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    SignificantTerms topTerms = response.getAggregations().get("mySignificantTerms");
    checkExpectedStringTermsFound(topTerms);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SignificantTermsIT.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ArtifactMetadataRetrievalException类代码示例发布时间:2022-05-21
下一篇:
Java ArithmeticUtils类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap