Search in sources :

Example 1 with MatchPhrasePrefixQueryBuilder

use of org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder in project elastest-torm by elastest.

the class ElasticsearchService method getFindMessageSearchRequest.

/* ************** */
/* *** Search *** */
/* ************** */
public SearchRequest getFindMessageSearchRequest(String index, String msg, String component) {
    BoolQueryBuilder componentStreamBoolBuilder = QueryBuilders.boolQuery();
    TermQueryBuilder componentTerm = QueryBuilders.termQuery("component", component);
    TermQueryBuilder streamTerm = QueryBuilders.termQuery("stream", "default_log");
    componentStreamBoolBuilder.must(componentTerm);
    componentStreamBoolBuilder.must(streamTerm);
    TermQueryBuilder streamTypeTerm = QueryBuilders.termQuery("stream_type", "log");
    MatchPhrasePrefixQueryBuilder messageMatchTerm = QueryBuilders.matchPhrasePrefixQuery("message", msg);
    BoolQueryBuilder shouldBoolBuilder = QueryBuilders.boolQuery();
    shouldBoolBuilder.should(componentStreamBoolBuilder);
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder.must(streamTypeTerm);
    boolQueryBuilder.must(messageMatchTerm);
    boolQueryBuilder.must(shouldBoolBuilder);
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.query(boolQueryBuilder);
    sourceBuilder.size(10000);
    sourceBuilder.sort(new FieldSortBuilder("@timestamp").order(SortOrder.ASC));
    sourceBuilder.sort(new FieldSortBuilder("_id").order(SortOrder.ASC));
    SearchRequest searchRequest = new SearchRequest(index);
    searchRequest.source(sourceBuilder);
    return searchRequest;
}
Also used : MatchPhrasePrefixQueryBuilder(org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Aggregations

SearchRequest (org.elasticsearch.action.search.SearchRequest)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 MatchPhrasePrefixQueryBuilder (org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder)1 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)1 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)1 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)1