當前位置: 首頁>>代碼示例>>Java>>正文


Java TermQueryBuilder類代碼示例

本文整理匯總了Java中org.elasticsearch.index.query.TermQueryBuilder的典型用法代碼示例。如果您正苦於以下問題:Java TermQueryBuilder類的具體用法?Java TermQueryBuilder怎麽用?Java TermQueryBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TermQueryBuilder類屬於org.elasticsearch.index.query包,在下文中一共展示了TermQueryBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的org.elasticsearch.index.query.TermQueryBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。