Search in sources :

Example 6 with TermQueryBuilder

use of org.elasticsearch.index.query.TermQueryBuilder in project elasticsearch by elastic.

the class SignificantTermsIT method testTextAnalysis.

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);
}
Also used : SignificantTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 7 with TermQueryBuilder

use of org.elasticsearch.index.query.TermQueryBuilder in project elasticsearch by elastic.

the class SignificantTermsIT method testPartiallyUnmapped.

public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx_unmapped", "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);
}
Also used : SignificantTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 8 with TermQueryBuilder

use of org.elasticsearch.index.query.TermQueryBuilder in project elasticsearch by elastic.

the class SignificantTermsIT method testStructuredAnalysis.

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)));
}
Also used : SignificantTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 9 with TermQueryBuilder

use of org.elasticsearch.index.query.TermQueryBuilder in project elasticsearch by elastic.

the class SignificantTermsIT method testStructuredAnalysisWithIncludeExclude.

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)));
}
Also used : SignificantTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 10 with TermQueryBuilder

use of org.elasticsearch.index.query.TermQueryBuilder in project elasticsearch by elastic.

the class SignificantTermsIT method testTextAnalysisGND.

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);
}
Also used : SignificantTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) GND(org.elasticsearch.search.aggregations.bucket.significant.heuristics.GND) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)38 SearchResponse (org.elasticsearch.action.search.SearchResponse)20 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)20 SignificantTerms (org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms)14 BytesReference (org.elasticsearch.common.bytes.BytesReference)7 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)6 Sampler (org.elasticsearch.search.aggregations.bucket.sampler.Sampler)6 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 DirectoryReader (org.apache.lucene.index.DirectoryReader)5 IndexWriter (org.apache.lucene.index.IndexWriter)5 Directory (org.apache.lucene.store.Directory)5 ElasticsearchDirectoryReader (org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader)5 ShardRequestCache (org.elasticsearch.index.cache.request.ShardRequestCache)5 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)5 WrapperQueryBuilder (org.elasticsearch.index.query.WrapperQueryBuilder)5 ShardId (org.elasticsearch.index.shard.ShardId)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Term (org.apache.lucene.index.Term)4 Bucket (org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms.Bucket)4