Summary

The queryAnalysis() GraphQL query analyzes a query string and returns diagnostic information.

Syntax

graphql
queryAnalysis(
      queryString: String!,
      languageVersion: LanguageVersionEnum!,
      isLive: Boolean!,
      viewName: String
   ): queryAnalysis!

Provide queryString, languageVersion, and isLive (all required). The optional viewName scopes the analysis to a specific view or repository. See the Input Parameters section for details.

Returns a non-nullable queryAnalysis object with diagnostic fields. See the Returned Values section for available fields.

Example

Raw
graphql
query {
  queryAnalysis(
     queryString: "host:localhost", 
     languageVersion: legacy, 
     isLive: true, 
     viewName:"humio")
  {filterPart, isAggregate, isSinglePhase}
}
Mac OS or Linux (curl)
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "query {
  queryAnalysis(
     queryString: \"host:localhost\", 
     languageVersion: legacy, 
     isLive: true, 
     viewName:\"humio\")
  {filterPart, isAggregate, isSinglePhase}
}"
}
EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "query {
  queryAnalysis(
     queryString: \"host:localhost\", 
     languageVersion: legacy, 
     isLive: true, 
     viewName:\"humio\")
  {filterPart, isAggregate, isSinglePhase}
}"
}
EOF
Windows Cmd and curl
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{"query" : "query { ^
  queryAnalysis( ^
     queryString: \"host:localhost\",  ^
     languageVersion: legacy,  ^
     isLive: true,  ^
     viewName:\"humio\") ^
  {filterPart, isAggregate, isSinglePhase} ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "query {
  queryAnalysis(
     queryString: \"host:localhost\", 
     languageVersion: legacy, 
     isLive: true, 
     viewName:\"humio\")
  {filterPart, isAggregate, isSinglePhase}
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $query = "query {
  queryAnalysis(
     queryString: \"host:localhost\", 
     languageVersion: legacy, 
     isLive: true, 
     viewName:\"humio\")
  {filterPart, isAggregate, isSinglePhase}
}";
$query =~ s/\n/ /g;
my $json = sprintf('{"query" : "%s"}',$query);
my $req = HTTP::Request->new("POST", $uri );

$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 = '$YOUR_LOGSCALE_URL/graphql'
mydata = r'''{"query" : "query {
  queryAnalysis(
     queryString: \"host:localhost\", 
     languageVersion: legacy, 
     isLive: true, 
     viewName:\"humio\")
  {filterPart, isAggregate, isSinglePhase}
}"
}'''

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

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

const data = JSON.stringify(
    {"query" : "query {
  queryAnalysis(
     queryString: \"host:localhost\", 
     languageVersion: legacy, 
     isLive: true, 
     viewName:\"humio\")
  {filterPart, isAggregate, isSinglePhase}
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL',
  path: 'graphql',
  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();
Example Responses
Success (HTTP Response Code 200 OK)
json
{
  "data": {
    "queryAnalysis": {
      "filterPart": "host:localhost",
      "isAggregate": false,
      "isSinglePhase": true
    }
  }
}

Input Parameters

Provide the required inputs: queryString, isLive, and languageVersion (for example, legacy). Optionally provide viewName to scope to a specific view.

Table: Input Parameters & Datatypes

Parameter Type Required Default Description
This table contains all input parameters for this query. Since one of the parameters uses a special datatype, an additional table is included below with its parameters.
isLive Boolean! yes   Whether the query is working with live data.
languageVersion LanguageVersionEnum yes   The version of the LogScale query language to use.
queryString String! yes   The query string to analyze.
viewName String     The name of the view or repository.

This special datatype indicates the language version (for example, legacy). Below is a list of choices along with a description of each:

Returned Values

Returns a non-nullable queryAnalysis object. isAggregate indicates whether the query contains an aggregator. isSinglePhase indicates whether the query contains no join-like function. filterPart is the query string up to the first aggregator. isValidFilterAlertQuery checks whether the query is suitable for a filter alert. drilldowns provides drill-down diagnostic information. The table below lists all fields:

Table: queryAnalysis Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
drilldownsdrilldownsyes Short-Term  
filterPartStringyes Short-Term The query string up to the first aggregator
isAggregateBooleanyes Short-Term The query contains an aggregator
isSinglePhaseBooleanyes Short-Term The query does not contain a join-like function or defineTable()