Creating an Index for a Specified Log Stream
Function
This API is used to create index configurations for a specified log stream. Full-text indexing and field indexing are supported. By configuring indexing, you can efficiently query and analyze logs, improving log retrieval speed.
Calling Method
For details, see Calling APIs.
URI
POST /v1.0/{project_id}/groups/{group_id}/stream/{stream_id}/index/config
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Definition Project ID. It can be obtained by calling an API or from the console. For details, see Obtaining a Project ID. Constraints N/A Range N/A Default Value N/A |
group_id |
Yes |
String |
Definition Log group ID. For details about how to obtain it, see Obtaining Log Group and Log Stream IDs. Constraints N/A Range N/A Default Value N/A |
stream_id |
Yes |
String |
Definition Log stream ID. For details about how to obtain it, see Obtaining Log Group and Log Stream IDs. Constraints N/A Range N/A Default Value N/A |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition User token obtained from IAM. For details about how to obtain it, see Obtaining a User Token. Constraints N/A Range N/A Default Value N/A |
Content-Type |
Yes |
String |
Definition Message body format. Set this parameter to application/json;charset=utf8. Constraints N/A Range N/A Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
logStreamId |
Yes |
String |
Definition Log stream ID. For details about how to obtain it, see Obtaining Log Group and Log Stream IDs. Constraints N/A Range N/A Default Value N/A |
fullTextIndex |
Yes |
LTSFullTextIndexInfo object |
Definition Full-text indexing configuration information. Constraints N/A |
fields |
No |
Array of LTSFieldsInfo objects |
Definition Field indexing configuration information. Constraints N/A |
sqlAnalysisEnable |
No |
Boolean |
Definition Whether to enable log analysis. Constraints N/A Range true: enables log analysis. false: disables log analysis. Default Value true |
fastAnalysisSampleCount |
No |
Long |
Definition Number of logs sampled for quick analysis. Constraints N/A Range Minimum value: 100000 Maximum value: 10000000 Default Value 100000 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
enable |
Yes |
Boolean |
Definition Whether to enable full-text indexing. Constraints N/A Range true: Full-text indexing is enabled. false: Full-text indexing is disabled. Default Value true |
caseSensitive |
Yes |
Boolean |
Definition Whether letters are case-sensitive when full-text indexing is enabled. Constraints N/A Range true: Letters are case-sensitive. false: Letters are case insensitive. Default Value false |
includeChinese |
Yes |
Boolean |
Definition Whether full-text indexing includes Chinese characters. Constraints N/A Range true: Chinese characters are included. false: Chinese characters are not included. Default Value false |
tokenizer |
Yes |
String |
Definition Delimiters. The log content can be split into multiple words based on the specified delimiters. If the default delimiters do not meet your requirements, use custom delimiters. Constraints N/A Range Minimum characters: 0 Maximum characters: 128 Default Value , '";=()[]{}@&<>/:\n\t\r |
ascii |
No |
Array of strings |
Definition ASCII delimiters. Enter ASCII values and characters by referring to ASCII Table. Constraints N/A Range Minimum characters: 1 Maximum characters: 3 Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
fieldType |
Yes |
String |
Definition Log field type for field indexing. Constraints N/A Range
Default Value string |
fieldName |
Yes |
String |
Definition Log field name for field indexing. Constraints
Range Field in the sample log. Default Value N/A |
caseSensitive |
No |
Boolean |
Definition Whether to enable case sensitivity for field indexing. Constraints N/A Range
Default Value false |
includeChinese |
No |
Boolean |
Definition Whether field indexing includes Chinese characters. Constraints N/A Range
Default Value false |
tokenizer |
Yes |
String |
Definition Custom delimiters. Constraints N/A Range N/A Default Value , '";=()[]{}@&<>/:\?\n\t\r |
quickAnalysis |
No |
Boolean |
Definition Whether to enable quick analysis for field indexing. Constraints
Range Default Value true |
ascii |
No |
Array of strings |
Definition ASCII delimiters. Constraints N/A |
ltsSubFieldsInfoList |
No |
Array of LTSSubFieldsInfo objects |
Definition Field information when the field type in the field index configuration is JSON. Constraints N/A |
fieldAnalysisAlias |
No |
String |
Definition Alias. After an alias is set, you can only use that alias for SQL search and analysis. However, it cannot be used for keyword search. Constraints N/A Range Maximum 256 characters. Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
fieldType |
Yes |
String |
Definition Log field type for field indexing. Constraints N/A Range
Default Value string |
fieldName |
Yes |
String |
Definition Log field name for field indexing. Constraints
Range Field in the sample log. Default Value N/A |
quickAnalysis |
No |
Boolean |
Definition Whether to enable quick analysis for field indexing. Constraints
Range Default Value true |
fieldAnalysisAlias |
No |
String |
Definition Alias. After an alias is set, you can only use that alias for SQL search and analysis. However, it cannot be used for keyword search. Constraints N/A Range Maximum 256 characters. Default Value N/A |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
errorCode |
String |
Definition Error code. For details, see Error Codes. Range N/A |
errorMessage |
String |
Definition Error message. Range N/A |
result |
String |
Definition Log stream ID. Range N/A |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
errorCode |
String |
Definition Error code. For details, see Error Codes. Range N/A |
errorMessage |
String |
Definition Error message. Range N/A |
Status code: 401
Parameter |
Type |
Description |
---|---|---|
errorCode |
String |
Definition Error code. For details, see Error Codes. Range N/A |
errorMessage |
String |
Definition Error message. Range N/A |
Status code: 500
Parameter |
Type |
Description |
---|---|---|
errorCode |
String |
Definition Error code. For details, see Error Codes. Range N/A |
errorMessage |
String |
Definition Error message. Range N/A |
Example Requests
Create an index for a specified log stream.
POST https://{endpoint}/v1.0/{project_id}/groups/{group_id}/stream/{stream_id}/index/config { "logStreamId" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "fullTextIndex" : { "enable" : true, "caseSensitive" : false, "includeChinese" : true, "tokenizer" : ", '\";=()[]{}@&<>/:\\n\\t\\r" }, "fields" : [ { "fieldType" : "long", "fieldName" : "fieldName1", "caseSensitive" : false, "includeChinese" : true, "tokenizer" : "", "quickAnalysis" : true }, { "fieldType" : "string", "fieldName" : "fieldName2", "caseSensitive" : false, "includeChinese" : true, "tokenizer" : "", "quickAnalysis" : true } ] }
Example Responses
Status code: 200
Indexing is added successfully.
{ "errorCode" : "SVCSTG.ALS.200200", "errorMessage" : "add or update indexConfig successfully", "result" : "493d04ce-5130-4b07-88be-c5ae3b50bccb" }
Status code: 400
Incorrect request parameter. Modify the parameter based on the response body.
{ "errorCode" : "SVCSTG.ALS.200201", "errorMessage" : "IndexConfigInfo check failed.", "isQueryComplete" : true }
Status code: 401
Authentication failed. Check whether the authentication information has expired.
{ "error_msg" : "Incorrect IAM authentication information: decrypt token fail", "error_code" : "APIGW.0301", "request_id" : "b16cc9d789f34cd5196d8df065341788" }
Status code: 500
The service backend has received the request, but an internal processing error occurs.
{ "highLightFields" : { }, "errorCode" : "LTS.0203", "errorMessage" : "Internal Server Error", "result" : null, "encoded_authorization_message" : null, "isQueryComplete" : true }
SDK Sample Code
The SDK sample code is as follows.
Create an index for a specified log stream.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.lts.v2.region.LtsRegion; import com.huaweicloud.sdk.lts.v2.*; import com.huaweicloud.sdk.lts.v2.model.*; import java.util.List; import java.util.ArrayList; public class CreateLogStreamIndexSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); LtsClient client = LtsClient.newBuilder() .withCredential(auth) .withRegion(LtsRegion.valueOf("<YOUR REGION>")) .build(); CreateLogStreamIndexRequest request = new CreateLogStreamIndexRequest(); request.withGroupId("{group_id}"); request.withStreamId("{stream_id}"); LTSIndexConfigInfo body = new LTSIndexConfigInfo(); List<LTSFieldsInfo> listbodyFields = new ArrayList<>(); listbodyFields.add( new LTSFieldsInfo() .withFieldType(LTSFieldsInfo.FieldTypeEnum.fromValue("long")) .withFieldName("fieldName1") .withCaseSensitive(false) .withIncludeChinese(true) .withTokenizer("") .withQuickAnalysis(true) ); listbodyFields.add( new LTSFieldsInfo() .withFieldType(LTSFieldsInfo.FieldTypeEnum.fromValue("string")) .withFieldName("fieldName2") .withCaseSensitive(false) .withIncludeChinese(true) .withTokenizer("") .withQuickAnalysis(true) ); LTSFullTextIndexInfo fullTextIndexbody = new LTSFullTextIndexInfo(); fullTextIndexbody.withEnable(true) .withCaseSensitive(false) .withIncludeChinese(true) .withTokenizer(", '";=()[]{}@&<>/:\n\t\r"); body.withLogStreamId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); body.withFields(listbodyFields); body.withFullTextIndex(fullTextIndexbody); request.withBody(body); try { CreateLogStreamIndexResponse response = client.createLogStreamIndex(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Create an index for a specified log stream.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdklts.v2.region.lts_region import LtsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdklts.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = LtsClient.new_builder() \ .with_credentials(credentials) \ .with_region(LtsRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateLogStreamIndexRequest() request.group_id = "{group_id}" request.stream_id = "{stream_id}" listFieldsbody = [ LTSFieldsInfo( field_type="long", field_name="fieldName1", case_sensitive=False, include_chinese=True, tokenizer="", quick_analysis=True ), LTSFieldsInfo( field_type="string", field_name="fieldName2", case_sensitive=False, include_chinese=True, tokenizer="", quick_analysis=True ) ] fullTextIndexbody = LTSFullTextIndexInfo( enable=True, case_sensitive=False, include_chinese=True, tokenizer=", '";=()[]{}@&<>/:\n\t\r" ) request.body = LTSIndexConfigInfo( log_stream_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", fields=listFieldsbody, full_text_index=fullTextIndexbody ) response = client.create_log_stream_index(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Create an index for a specified log stream.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" lts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := lts.NewLtsClient( lts.LtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateLogStreamIndexRequest{} request.GroupId = "{group_id}" request.StreamId = "{stream_id}" caseSensitiveFields:= false includeChineseFields:= true quickAnalysisFields:= true caseSensitiveFields1:= false includeChineseFields1:= true quickAnalysisFields1:= true var listFieldsbody = []model.LtsFieldsInfo{ { FieldType: model.GetLtsFieldsInfoFieldTypeEnum().LONG, FieldName: "fieldName1", CaseSensitive: &caseSensitiveFields, IncludeChinese: &includeChineseFields, Tokenizer: "", QuickAnalysis: &quickAnalysisFields, }, { FieldType: model.GetLtsFieldsInfoFieldTypeEnum().STRING, FieldName: "fieldName2", CaseSensitive: &caseSensitiveFields1, IncludeChinese: &includeChineseFields1, Tokenizer: "", QuickAnalysis: &quickAnalysisFields1, }, } fullTextIndexbody := &model.LtsFullTextIndexInfo{ Enable: true, CaseSensitive: false, IncludeChinese: true, Tokenizer: ", '";=()[]{}@&<>/:\n\t\r", } request.Body = &model.LtsIndexConfigInfo{ LogStreamId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", Fields: &listFieldsbody, FullTextIndex: fullTextIndexbody, } response, err := client.CreateLogStreamIndex(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
200 |
Indexing is added successfully. |
400 |
Incorrect request parameter. Modify the parameter based on the response body. |
401 |
Authentication failed. Check whether the authentication information has expired. |
500 |
The service backend has received the request, but an internal processing error occurs. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot