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;
}
Aggregations