Summary

The addFieldAliasMapping() mutation adds a field alias mapping to a schema. On success, it returns the string ID of the new alias mapping. Each call adds one mapping. To update a mapping, use updateFieldAliasMapping() instead.

Syntax

graphql
addFieldAliasMapping(
      input: AddAliasMappingInput!
   ): String!

The mutation takes a single required input argument of type AddAliasMappingInput. Provide the schema identifier and the alias mapping details. The return type String! is non-nullable: the mutation returns the ID of the new alias mapping on success.

Example

Raw
graphql
mutation {
  addFieldAliasMapping(
      schemaId: "123", 
      aliasMapping: {
        name: "ECS for HAProxy", 
        tags: [ {name: "kind", value: "logs"}, 
                {name: "repo", value: "github"} ],
        aliases: [ {source: "port", alias: "source.port"} ]
      } 
  )
}
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" : "mutation {
  addFieldAliasMapping(
      schemaId: \"123\", 
      aliasMapping: {
        name: \"ECS for HAProxy\", 
        tags: [ {name: \"kind\", value: \"logs\"}, 
                {name: \"repo\", value: \"github\"} ],
        aliases: [ {source: \"port\", alias: \"source.port\"} ]
      } 
  )
}"
}
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" : "mutation {
  addFieldAliasMapping(
      schemaId: \"123\", 
      aliasMapping: {
        name: \"ECS for HAProxy\", 
        tags: [ {name: \"kind\", value: \"logs\"}, 
                {name: \"repo\", value: \"github\"} ],
        aliases: [ {source: \"port\", alias: \"source.port\"} ]
      } 
  )
}"
}
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" : "mutation { ^
  addFieldAliasMapping( ^
      schemaId: \"123\",  ^
      aliasMapping: { ^
        name: \"ECS for HAProxy\",  ^
        tags: [ {name: \"kind\", value: \"logs\"},  ^
                {name: \"repo\", value: \"github\"} ], ^
        aliases: [ {source: \"port\", alias: \"source.port\"} ] ^
      }  ^
  ) ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  addFieldAliasMapping(
      schemaId: \"123\", 
      aliasMapping: {
        name: \"ECS for HAProxy\", 
        tags: [ {name: \"kind\", value: \"logs\"}, 
                {name: \"repo\", value: \"github\"} ],
        aliases: [ {source: \"port\", alias: \"source.port\"} ]
      } 
  )
}"
}'
    "$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 = "mutation {
  addFieldAliasMapping(
      schemaId: \"123\", 
      aliasMapping: {
        name: \"ECS for HAProxy\", 
        tags: [ {name: \"kind\", value: \"logs\"}, 
                {name: \"repo\", value: \"github\"} ],
        aliases: [ {source: \"port\", alias: \"source.port\"} ]
      } 
  )
}";
$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" : "mutation {
  addFieldAliasMapping(
      schemaId: \"123\", 
      aliasMapping: {
        name: \"ECS for HAProxy\", 
        tags: [ {name: \"kind\", value: \"logs\"}, 
                {name: \"repo\", value: \"github\"} ],
        aliases: [ {source: \"port\", alias: \"source.port\"} ]
      } 
  )
}"
}'''

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" : "mutation {
  addFieldAliasMapping(
      schemaId: \"123\", 
      aliasMapping: {
        name: \"ECS for HAProxy\", 
        tags: [ {name: \"kind\", value: \"logs\"}, 
                {name: \"repo\", value: \"github\"} ],
        aliases: [ {source: \"port\", alias: \"source.port\"} ]
      } 
  )
}"
}
);


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": {
    "addFieldAliasMapping": "def456"
  },
}

Input Parameters

Provide the schema identifier and the alias mapping to add. Use fieldAliasSchemas() to retrieve the schemaId value. The aliasMapping field takes an AliasMappingInput object that defines the mapping name, tags, aliases, and original fields to keep. Each alias entry in the aliases list pairs a source field name with its alias using AliasInfoInput. Each tag in the tags list is a name-value pair using TagsInput.

Table: AddAliasMappingInput Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
aliasMappingAliasMappingInputyes Long-Term The alias mapping to be added to the schema. See AliasMappingInput.
schemaIdStringyes Long-Term The unique identifier of the schema on which the alias mapping exists.

Table: AliasMappingInput Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
aliasesAliasInfoInputyes Long-Term List of aliases. See AliasInfoInput.
nameStringyes Long-Term The name of the alias map.
originalFieldsToKeepStringyes Long-Term List of original fields to keep.
tagsTagsInputyes Long-Term Tags for alias mapping. See TagsInput.

Table: AliasInfoInput Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
aliasStringyes Long-Term The alias. See TagsInput.
sourceStringyes Long-Term The source of the alias information.

Table: TagsInput Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
nameStringyes Long-Term The name of the tag.
valueStringyes Long-Term The value of the tag.

Returned Values

The mutation returns the string ID of the newly created alias mapping. Pass this ID to updateFieldAliasMapping() or removeFieldAliasMapping() to manage the mapping after creation.