Creating a Query Job

To create a query through the Query Jobs interface you must submit a POST:

Description Create a query job  
MethodPOST /api/v1/repositories/repo/queryjobs/id 
Request DataQueryJobInput 
Response DataQueryResults 
Authentication Requiredyes 
Path ArgumentsDescriptionData typeRequired?
id ID of the query job stringrequired
repo Name of repository or view to be searched stringrequired
Return Codes 
200 Request complete  
400 Request is malformed and either missing critical fields or the JSON is badly structured  
500 Request failed  

The JSON request body supports the following attributes:

Table: QueryJobInput JSON Object Fields

FieldTypeAvailabilityRequired?DefaultDescription
allowEventSkippingboolean    Some LogScale functions, such as head() and tail(), automatically stop processing all data in the selected timeframe and exit the query early, if more data would no longer change the result of the query. This improves performance of the query. Setting allowEventSkipping to true, forces event skipping in all circumstances. For example, when the showQueryEventDistribution or doneCriteria.minimumMatchedEvents parameters are set, event skipping is disabled by default to ensure accurate event counts, but setting allowEventSkipping to true overrides this, and forces skipping.
argumentsobject    Dictionary of arguments specified in queries with ?param or ?{param=defaultValue} syntax. Provided arguments must be a simple dictionary of string values. If an argument is given explicitly as in ?query(param=value) then that value overrides values provided here.
aroundobject    Used to define the pagination of events in the result set within the given query when using pagination. Used for cursor-based paginating of filter query result. This cannot be used with aggregate results as all rows are always returned. For more information see api-search-request-around
autobucketCountinteger    Determines the number of buckets the system should create during live query searches, when no other explicit bucketing aggregate is specified (such as bucket(), timeChart()). Higher autobucket counts means finer granularity, but at the cost of increased memory usage during search.
computeFieldStatsboolean    If set to true, computeFieldStats causes LogScale to calculate a map of all fields of the result and their top ten most common values, along with both the total number of occurrences for the field, as well as its values. These results are returned as part of the QueryResult JSON object under the field fieldStats. This field is always present, but empty if not requested in the query input for the query.
dashboardFilterstring    The ID of a query. This parameter is used to apply a dashboard filter to a query. In LogScale, a dashboard filter is a regular query which is applied to all queries on a dashboard, usually prefixing the dashboard widget query. But this is not always the case, so it can also be passed to the Query API to be able to merge the query and the dashboard filter to form a complete query. When querying the Query API from other clients, that would mean that the dashboardFilter parameter can be used when you have a set of queries where the start of each query is identical. You can then extract the duplicated part of the query and pass that as a dashboardFilter instead, ensuring that it will be applied correctly even though you use a query function with special semantics that require it to be at the start of the query, such as defineTable().
dashboardFilterVersionstring    
doneCriteria(from 1.141)   
        fractionOfDataScannednumber    The query is considered done when least X percent of the input data is sampled. It should be a number in the range ]0;1] where 1 mean all events (100%) and e.g. 0.1 is approximately 10% of data that will be scanned. Sampling is done based on event size and not the number of events.
        minimumMatchedEventsinteger    The query is done once at least X events have matched the filters before the first aggregation. This can be useful if you just want to show some candidates or you consider a result to be good enough when at least X events have been considered.
        minimumResultRowsinteger    The query is done once at least X rows are present in the output. Note that if this criterion is used in conjunction with an aggregate function there is no guarantee for how good the output results are as we don't know how much data was processed to produce the result. But it is useful for e.g. find 10 events that match this filter, similar to tail(), but does not guarantee that the most recent matches are returned.
end    The end date and time. This parameter tells LogScale not to return results from after this date and time. See how to specify a time.
extraLogFieldsobject   

Extra fields set on a query that are logged to the audit and activity logs as customKey.

The following rules apply to both the key and value fields:

  • Maximum length is 512 characters.

  • Only the following characters are permitted: a-z, A-Z, 0-9, and the special characters , - . _

To learn more, see extraLogFields.

includeDeletedEventsboolean    
ingestEnd    Specifies the end time based on when the data was ingested. See how to specify a time.
ingestStart    Specifies the start time based on when the data was ingested. See how to specify a time.
isAlertQueryboolean    Indicates whether the query comes from an alert or not.
isInteractiveboolean    Whether the search is being run interactively, i.e., from with the LogScale or another UI.
isLiveboolean    Sets whether this query is live. Defaults to false . Live queries are continuously updated.
isRepeatingSubqueryboolean    
languageVersionstring    The version of the query language to use
nextRunIntervalobject   

This parameter enables you to supply a hint to the query engine that the next run of the query will have an interval specified by the given start and end values.

This information may be used to speed up the repeated runs of the query by allowing partial reuse of query results.

Usage example:

json
{ [...] "nextRunInterval": { "start": 1764765006226, "end": 1764851406227 } }
noResultUntilDoneboolean    If true, no events are included in responses to polls until the static part of the query has completed, at which point the full result set is returned. Metadata and progress information are updated on each poll.
queryStringstring Yes  The actual query. See Query Language Syntax for details.
showQueryEventDistributionboolean    If true LogScale will return an additional resultset containing a histogram of the number of events over the time interval. Use results instead. If both this field and results are specified, results takes precedence.
start    The start date and time. This parameter tells LogScale not to return results from before this date and time. See how to specify a time.
timeZonestring    The timezone to be used when returning dates.
timeZoneOffsetMinutesinteger    Set the time zone offset used for bucket() and timeChart() time slices, which is significant if the corresponding span is multiples of days. Defaults to 0 (UTC); positive numbers are to the east of UTC, so for UTC+01:00 timezone the value 60 should be passed.
useIngestTimeboolean    When set to true, uses the ingest time rather than event timestamp as the basis for the time span, to control sorting/bucketing for functions like bucket(). Note that when true, the time window set by both ingestStart and ingestEnd will be applied, in addition to the time window set by start and end, the effective time window being the intersection of these two time windows.
wantsAutoBucketingboolean    

The request for the query matches the simple query JSON fields. See Streaming Search Request for more information on the supported arguments.

Raw
json
{
   "queryString" : "",
   "showQueryEventDistribution" : true,
   "isLive" : false,
   "start" : "1d"
}
Mac OS or Linux (curl)
shell
curl -v -X POST https://$YOUR_LOGSCALE_URL/api/v1/repositories/$REPOSITORY_NAME/queryjobs \
    -H "Accept: application/json" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{
   "isLive" : false,
   "start" : "1d",
   "showQueryEventDistribution" : true,
   "queryString" : ""
}

EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST https://$YOUR_LOGSCALE_URL/api/v1/repositories/$REPOSITORY_NAME/queryjobs \
    -H "Accept: application/json" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{
   \"isLive\" : false,
   \"start\" : \"1d\",
   \"showQueryEventDistribution\" : true,
   \"queryString\" : \"\"
}

EOF
Windows Cmd and curl
shell
curl -v -X POST https://$YOUR_LOGSCALE_URL/api/v1/repositories/$REPOSITORY_NAME/queryjobs ^
    -H "Accept: application/json" ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{ ^
   \"showQueryEventDistribution\" : true, ^
   \"queryString\" : \"\", ^
   \"isLive\" : false, ^
   \"start\" : \"1d\" ^
} ^
 '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Accept: application/json"
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{
   \"start\" : \"1d\",
   \"isLive\" : false,
   \"showQueryEventDistribution\" : true,
   \"queryString\" : \"\"
}
'
    "https://$YOUR_LOGSCALE_URL/api/v1/repositories/$REPOSITORY_NAME/queryjobs"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = 'https://$YOUR_LOGSCALE_URL/api/v1/repositories/$REPOSITORY_NAME/queryjobs';

my $json = '{
   \"isLive\" : false,
   \"start\" : \"1d\",
   \"queryString\" : \"\",
   \"showQueryEventDistribution\" : true
}
';
my $req = HTTP::Request->new("POST", $uri );

$req->header("Accept" => "application/json");
$req->header("Authorization" => "Bearer $TOKEN");
$req->header("Content-Type" => "application/json");

$req->content( $json );

my $lwp = LWP::UserAgent->new;

my $result = $lwp->request( $req );

print $result->{"_content"},"\n";
Python
python
#! /usr/local/bin/python3

import requests

url = 'https://$YOUR_LOGSCALE_URL/api/v1/repositories/$REPOSITORY_NAME/queryjobs'
mydata = r'''{
   "queryString" : "",
   "showQueryEventDistribution" : true,
   "isLive" : false,
   "start" : "1d"
}
'''

resp = requests.post(url,
                     data = mydata,
                     headers = {
   "Accept" : "application/json",
   "Authorization" : "Bearer $TOKEN",
   "Content-Type" : "application/json"
}
)

print(resp.text)
Node.js
javascript
const https = require('https');

const data = JSON.stringify(
    {
   \"queryString\" : \"\",
   \"showQueryEventDistribution\" : true,
   \"isLive\" : false,
   \"start\" : \"1d\"
}

);


const options = {
  hostname: 'https:',
  path: '/$YOUR_LOGSCALE_URL/api/v1/repositories/$REPOSITORY_NAME/queryjobs',
  port: 443,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length,
    Authorization: 'BEARER ' + process.env.TOKEN,
    'User-Agent': 'Node',
  },
};

const req = https.request(options, (res) => {
  let data = '';
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    data += d;
  });
  res.on('end', () => {
    console.log(JSON.parse(data).data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();

When creating a query job, an ID is returned that identified the query job. The id field indicates the {id} for the query, which you can then poll using the HTTP GET method (see Polling a Query Job).

http
{
   "hashedQueryOnView" : "4ab13fa1",
   "id" : "P15-uoxCpi2DFJDFTAkHXLyYL8bN"
}

The returned JSON uses the following schema:

Table: Metadata JSON Object Fields

FieldTypeAvailabilityDescription
hashedQueryOnViewstring  A string hash of the optimized query (the "query plan"). For advanced users.
idstring  The id of the started queryjob. This can be used to poll results.
queryOnViewstring  A string representation of the optimized query (the "query plan"). For advanced users.
staticMetaDataobject  If provided, indicates that the backend is running the query in a special mode, and may include information about the reason for selecting that mode.

An OpenAPI specification for this interface is available: Download it here. This can be used with a number of languages to build clients for this data.