use of org.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class V20161116172200_CreateDefaultStreamMigration method createDefaultStream.
private void createDefaultStream() {
final IndexSet indexSet = indexSetRegistry.getDefault();
final ObjectId id = new ObjectId(Stream.DEFAULT_STREAM_ID);
final Map<String, Object> fields = ImmutableMap.<String, Object>builder().put(StreamImpl.FIELD_TITLE, "All messages").put(StreamImpl.FIELD_DESCRIPTION, "Stream containing all messages").put(StreamImpl.FIELD_DISABLED, false).put(StreamImpl.FIELD_CREATED_AT, DateTime.now(DateTimeZone.UTC)).put(StreamImpl.FIELD_CREATOR_USER_ID, "local:admin").put(StreamImpl.FIELD_MATCHING_TYPE, StreamImpl.MatchingType.DEFAULT.name()).put(StreamImpl.FIELD_REMOVE_MATCHES_FROM_DEFAULT_STREAM, false).put(StreamImpl.FIELD_DEFAULT_STREAM, true).put(StreamImpl.FIELD_INDEX_SET_ID, indexSet.getConfig().id()).build();
final Stream stream = new StreamImpl(id, fields, Collections.emptyList(), Collections.emptySet(), indexSet);
try {
streamService.save(stream);
LOG.info("Successfully created default stream: {}", stream.getTitle());
} catch (ValidationException e) {
LOG.error("Couldn't create default stream! This is a bug!");
}
}
use of org.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class AbsoluteSearchResource method searchAbsolute.
@GET
@Timed
@ApiOperation(value = "Message search with absolute timerange.", notes = "Search for messages using an absolute timerange, specified as from/to " + "with format yyyy-MM-ddTHH:mm:ss.SSSZ (e.g. 2014-01-23T15:34:49.000Z) or yyyy-MM-dd HH:mm:ss.")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid timerange parameters provided.") })
public SearchResponse searchAbsolute(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "from", value = "Timerange start. See description for date format", required = true) @QueryParam("from") @NotEmpty String from, @ApiParam(name = "to", value = "Timerange end. See description for date format", required = true) @QueryParam("to") @NotEmpty String to, @ApiParam(name = "limit", value = "Maximum number of messages to return.") @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset") @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter") @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return") @QueryParam("fields") String fields, @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)") @QueryParam("sort") String sort, @ApiParam(name = "decorate", value = "Run decorators on search result") @QueryParam("decorate") @DefaultValue("true") boolean decorate, @Context SearchUser searchUser) {
checkSearchPermission(filter, RestPermissions.SEARCHES_ABSOLUTE);
final Sort sorting = buildSortOrder(sort);
final List<String> fieldList = parseOptionalFields(fields);
final TimeRange timeRange = buildAbsoluteTimeRange(from, to);
return search(query, limit, filter, decorate, searchUser, fieldList, sorting, timeRange);
}
use of org.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class KeywordSearchResource method searchKeyword.
@GET
@Timed
@ApiOperation(value = "Message search with keyword as timerange.", notes = "Search for messages in a timerange defined by a keyword like \"yesterday\" or \"2 weeks ago to wednesday\".")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid keyword provided.") })
public SearchResponse searchKeyword(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "keyword", value = "Range keyword", required = true) @QueryParam("keyword") @NotEmpty String keyword, @QueryParam("timezone") @NotEmpty String timezone, @ApiParam(name = "limit", value = "Maximum number of messages to return.") @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset") @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter") @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return") @QueryParam("fields") String fields, @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)") @QueryParam("sort") String sort, @ApiParam(name = "decorate", value = "Run decorators on search result") @QueryParam("decorate") @DefaultValue("true") boolean decorate, @Context SearchUser searchUser) {
checkSearchPermission(filter, RestPermissions.SEARCHES_KEYWORD);
final Sort sorting = buildSortOrder(sort);
final List<String> fieldList = parseOptionalFields(fields);
final TimeRange timeRange = buildKeywordTimeRange(keyword, timezone);
return search(query, limit, filter, decorate, searchUser, fieldList, sorting, timeRange);
}
use of org.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class RelativeSearchResource method searchRelative.
@GET
@Timed
@ApiOperation(value = "Message search with relative timerange.", notes = "Search for messages in a relative timerange, specified as seconds from now. " + "Example: 300 means search from 5 minutes ago to now.")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid timerange parameters provided.") })
@Produces(MediaType.APPLICATION_JSON)
public SearchResponse searchRelative(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "range", value = "Relative timeframe to search in. See method description.", required = true) @QueryParam("range") @PositiveOrZero int range, @ApiParam(name = "limit", value = "Maximum number of messages to return.") @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset") @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter") @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return") @QueryParam("fields") String fields, @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)") @QueryParam("sort") String sort, @ApiParam(name = "decorate", value = "Run decorators on search result") @QueryParam("decorate") @DefaultValue("true") boolean decorate, @Context SearchUser searchUser) {
checkSearchPermission(filter, RestPermissions.SEARCHES_RELATIVE);
final List<String> fieldList = parseOptionalFields(fields);
final Sort sorting = buildSortOrder(sort);
final TimeRange timeRange = buildRelativeTimeRange(range);
return search(query, limit, filter, decorate, searchUser, fieldList, sorting, timeRange);
}
use of org.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class RelativeSearchResource method searchRelativeChunked.
@GET
@Timed
@ApiOperation(value = "Message search with relative timerange.", notes = "Search for messages in a relative timerange, specified as seconds from now. " + "Example: 300 means search from 5 minutes ago to now.")
@Produces(MoreMediaTypes.TEXT_CSV)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid timerange parameters provided.") })
public ChunkedOutput<ScrollResult.ScrollChunk> searchRelativeChunked(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "range", value = "Relative timeframe to search in. See method description.", required = true) @QueryParam("range") @PositiveOrZero int range, @ApiParam(name = "limit", value = "Maximum number of messages to return.", required = false) @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset", required = false) @QueryParam("offset") int offset, @ApiParam(name = "batch_size", value = "Batch size for the backend storage export request.", required = false) @QueryParam("batch_size") @DefaultValue(DEFAULT_SCROLL_BATCH_SIZE) int batchSize, @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return", required = true) @QueryParam("fields") @NotEmpty String fields) {
checkSearchPermission(filter, RestPermissions.SEARCHES_RELATIVE);
final List<String> fieldList = parseFields(fields);
final TimeRange timeRange = buildRelativeTimeRange(range);
final ScrollResult scroll = searches.scroll(query, timeRange, limit, offset, fieldList, filter, batchSize);
return buildChunkedOutput(scroll);
}
Aggregations