--- tags: elasticsearch --- # Agocean index 建立初始化腳本(ILM、Rollover) ## !!注意!!只限初始建立使用 ``` #!/bin/bash # Elasticsearch 初始化建立 Template index #----------------------------------------------ENV------------------------------------------------ #運作環境 # PROJECT_ENV PROJECT_ENV="test"; #遊戲工作室 # GAME_STUDIOS GAME_STUDIOS=${GAMESTUDIO:=' [ {"gameStudio":"ht"} ] '}; #系統服務(待補充) #ELK 連線資料 # ELASTICSEARCH_HOST # ELASTIC_USER # ELASTIC_TOKEN TMP_RESPNOSE_FILE="response.txt"; ## prod ace-club # ELASTICSEARCH_HOST="https://0a17b4e3ae7a444e819820c279b3e02a.asia-east1.gcp.elastic-cloud.com:9243/"; # ELASTIC_USER="elastic"; # ELASTIC_TOKEN="KSHu7q82lVsBAzHBQfLlJZx2"; ## dev、stage、sandbox ELASTICSEARCH_HOST="https://e8878ca4e297419c800c5a81e0b53411.asia-east1.gcp.elastic-cloud.com:9243/"; ELASTIC_USER="elastic"; ELASTIC_TOKEN="QGjn8pOnEvymkMiYrVP6X34E"; #------------------------------------------------ILM---------------------------------------------# # ILM 設定 # HOT: after 3 Day # WARM: after 31 Day # COLD: after 93 Day # DELETE: after 105 Day ELK_ILM_POLICY="_ilm/policy/agocean-$PROJECT_ENV-ilm"; ELK_COMMON_GAMERECORD_ILM_POLICY="_ilm/policy/agocean-$PROJECT_ENV-game-ilm"; ELASTICSEARCH_HOST_ILM="$ELASTICSEARCH_HOST""$ELK_ILM_POLICY"; ILM_HOT_KEEP="24h"; ILM_WARM_KEEP="24h"; ILM_COLD_KEEP="31d"; ILM_DELETE_KEEP="93d"; #CREATE COMMON ILM ILM_API_DATA='{"policy": {"phases": {"hot": {"min_age": "0ms","actions": {"rollover": {"max_age": "'$ILM_HOT_KEEP'","max_size": "50gb"},"set_priority": {"priority": 100}}},"warm": {"min_age": "'$ILM_WARM_KEEP'","actions": {"allocate": {"require": {"data": "warm"},"number_of_replicas": 1},"shrink": {"number_of_shards": 1},"set_priority": {"priority": 50}}},"cold": {"min_age": "'$ILM_COLD_KEEP'","actions": {"freeze": {},"set_priority": {"priority": 0}}},"delete": {"min_age": "'$ILM_DELETE_KEEP'","actions": {}}}}}'; curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$ILM_API_DATA" \ $ELASTICSEARCH_HOST_ILM echo " $ELK_ILM_POLICY response"; #CREATE GAME_RECORD ILM ELASTICSEARCH_HOST_ILM="$ELASTICSEARCH_HOST""$ELK_COMMON_GAMERECORD_ILM_POLICY"; ILM_API_DATA='{"policy": {"phases": {"hot": {"min_age": "0ms","actions": {"rollover": {"max_age": "24h","max_size": "50gb"},"set_priority": {"priority": 100}}},"warm": {"min_age": "24h","actions": {"allocate": {"require": {"data": "warm"},"number_of_replicas": 1},"shrink": {"number_of_shards": 1},"set_priority": {"priority": 50}}},"cold": {"min_age": "7d","actions": {"freeze": {},"set_priority": {"priority": 0}}},"delete": {"min_age": "14d","actions": {}}}}}'; curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$ILM_API_DATA" \ $ELASTICSEARCH_HOST_ILM echo " $ELK_COMMON_GAMERECORD_ILM_POLICY response"; #--------------------------------------------TEMPLATE-------------------------------------------------# # TEMPLATE 設定 ELK_COMMON_TEMPLATE="_template/agocean-$PROJECT_ENV"; ELK_COMMON_GAME_TEMPLATE="_template/agocean-$PROJECT_ENV-game"; ELK_COMMON_GAME_EVENT_TEMPLATE="_template/agocean-$PROJECT_ENV-game-event"; #CREATE COMMON TEMPLATE ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_COMMON_TEMPLATE"; TEMPLATE_DATA='{"order" : 1,"index_patterns" : ["agocean-'$PROJECT_ENV'-*"],"settings" : {"index" : {"lifecycle": {"name": "agocean-'$PROJECT_ENV'-ilm","rollover_alias": "agocean-'$PROJECT_ENV'"},"codec" : "best_compression","mapping" : {"total_fields" : {"limit" : "2000"},"ignore_malformed" : "true"},"number_of_shards" : "3","number_of_replicas" : "1","max_docvalue_fields_search" : "1000"}},"mappings" : {"_routing" : {"required" : false},"numeric_detection" : false,"dynamic_date_formats" : ["strict_date_optional_time","yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z"],"_meta" : { },"_source" : {"excludes" : [ ],"includes" : [ ],"enabled" : true},"dynamic" : true,"dynamic_templates" : [ {"integers": {"mapping": {"type": "float"},"path_unmatch": "log.*","match_mapping_type": "long"}}],"date_detection" : true},"aliases" : { }}'; curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_COMMON_TEMPLATE response"; #CREATE GAME TEMPLATE ELASTICSEARCH_HOST_GAME_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_COMMON_GAME_TEMPLATE"; TEMPLATE_DATA='{"order" : 50,"index_patterns" : ["agocean-'$PROJECT_ENV'-game-*"],"settings" : {"index" : {"lifecycle": {"name": "agocean-'$PROJECT_ENV'-game-ilm"},"codec" : "best_compression","mapping" : {"ignore_malformed" : "true"},"number_of_shards" : "3","number_of_replicas" : "1","max_docvalue_fields_search" : "1000"}}}'; curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_GAME_TEMPLATE echo " $ELK_COMMON_GAME_TEMPLATE response"; #CREATE GAME TEMPLATE ELASTICSEARCH_HOST_GAME_EVENT_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_COMMON_GAME_EVENT_TEMPLATE"; TEMPLATE_DATA='{"order" : 100,"index_patterns" : ["agocean-'$PROJECT_ENV'-game-event-*"]}'; curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_GAME_EVENT_TEMPLATE echo " $ELK_COMMON_GAME_EVENT_TEMPLATE response"; #----------------------------------------------INDEX----------------------------------------------------- #----------------------------------------------default ELK_DEFAULT_TEMPLATE="_template/agocean-$PROJECT_ENV-default"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_DEFAULT_TEMPLATE"; TEMPLATE_DATA='{"order" : 150,"index_patterns" : ["agocean-'$PROJECT_ENV'-default-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-default"}}}'; ## template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELASTICSEARCH_HOST_TEMPLATE response"; ## index ELK_COMMON_INDEX="agocean-$PROJECT_ENV-default-000001"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_COMMON_INDEX"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-default": {"is_write_index": true}}}}'; curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_COMMON_INDEX response"; #----------------------------------------------AccountSystem #common ELK_ACCOUNTSYSTEM_INDEX="agocean-$PROJECT_ENV-accountsystem-000001"; ELK_ACCOUNTSYSTEM_TEMPLATE="_template/agocean-$PROJECT_ENV-accountsystem"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_ACCOUNTSYSTEM_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_ACCOUNTSYSTEM_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-accountsystem": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 150,"index_patterns" : ["agocean-'$PROJECT_ENV'-accountsystem-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-accountsystem"}}}'; ## template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELASTICSEARCH_HOST_TEMPLATE response"; ## index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_ACCOUNTSYSTEM_INDEX response"; #event ELK_ACCOUNTSYSTEM_INDEX="agocean-$PROJECT_ENV-accountsystem-event-000001"; ELK_ACCOUNTSYSTEM_TEMPLATE="_template/agocean-$PROJECT_ENV-accountsystem-event"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_ACCOUNTSYSTEM_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_ACCOUNTSYSTEM_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-accountsystem-event": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 200,"index_patterns" : ["agocean-'$PROJECT_ENV'-accountsystem-event-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-accountsystem-event"}}}'; ## template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_ACCOUNTSYSTEM_TEMPLATE response"; ## index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_ACCOUNTSYSTEM_INDEX response"; #----------------------------------------------api-inbound ##common ELK_API_INBOUND_INDEX="agocean-$PROJECT_ENV-api-inbound-000001"; ELK_API_INBOUND_TEMPLATE="_template/agocean-$PROJECT_ENV-api-inbound"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_API_INBOUND_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_API_INBOUND_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-api-inbound": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 150,"index_patterns" : ["agocean-'$PROJECT_ENV'-api-inbound-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-api-inbound"}}}'; ### template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_API_INBOUND_TEMPLATE response"; ### index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_API_INBOUND_INDEX response"; ##event ELK_API_INBOUND_INDEX="agocean-$PROJECT_ENV-api-inbound-event-000001"; ELK_API_INBOUND_TEMPLATE="_template/agocean-$PROJECT_ENV-api-inbound-event"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_API_INBOUND_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_API_INBOUND_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-api-inbound-event": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 200,"index_patterns" : ["agocean-'$PROJECT_ENV'-api-inbound-event-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-api-inbound-event"}}}'; ### template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_API_INBOUND_TEMPLATE response"; ### index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_API_INBOUND_INDEX response"; #----------------------------------------------dummy-integrator #common ELK_DUMMY_INTEGRATOR_INDEX="agocean-$PROJECT_ENV-dummy-integrator-000001"; ELK_DUMMY_INTEGRATOR_TEMPLATE="_template/agocean-$PROJECT_ENV-dummy-integrator"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_DUMMY_INTEGRATOR_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_DUMMY_INTEGRATOR_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-dummy-integrator": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 150,"index_patterns" : ["agocean-'$PROJECT_ENV'-dummy-integrator-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-dummy-integrator"}}}'; ### template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_DUMMY_INTEGRATOR_TEMPLATE response"; ### index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_DUMMY_INTEGRATOR_INDEX response"; ##event ELK_DUMMY_INTEGRATOR_EVENT_INDEX="agocean-$PROJECT_ENV-dummy-integrator-event-000001"; ELK_DUMMY_INTEGRATOR_TEMPLATE="_template/agocean-$PROJECT_ENV-dummy-integrator-event"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_DUMMY_INTEGRATOR_EVENT_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_DUMMY_INTEGRATOR_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-dummy-integrator-event": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 200,"index_patterns" : ["agocean-'$PROJECT_ENV'-dummy-integrator-event-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-dummy-integrator-event"}}}'; ### template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_DUMMY_INTEGRATOR_TEMPLATE response"; ### index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_DUMMY_INTEGRATOR_EVENT_INDEX response"; #----------------------------------------------grpcbridge #common ELK_GRPCBRIDGE_INDEX="agocean-$PROJECT_ENV-grpcbridge-000001"; ELK_GRPCBRIDGE_TEMPLATE="_template/agocean-$PROJECT_ENV-grpcbridge"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_GRPCBRIDGE_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_GRPCBRIDGE_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-grpcbridge": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 150,"index_patterns" : ["agocean-'$PROJECT_ENV'-grpcbridge-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-grpcbridge"}}}'; ### template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_GRPCBRIDGE_TEMPLATE response"; ### index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_GRPCBRIDGE_INDEX response"; #event ELK_GRPCBRIDGE_INDEX="agocean-$PROJECT_ENV-grpcbridge-event-000001"; ELK_GRPCBRIDGE_TEMPLATE="_template/agocean-$PROJECT_ENV-grpcbridge-event"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_GRPCBRIDGE_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_GRPCBRIDGE_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-grpcbridge-event": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 200,"index_patterns" : ["agocean-'$PROJECT_ENV'-grpcbridge-event-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-grpcbridge-event"}}}'; ### template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_GRPCBRIDGE_TEMPLATE response"; ### index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_GRPCBRIDGE_INDEX response"; #----------------------------------------------geme-record-cache #common ELK_GRPCBRIDGE_INDEX="agocean-$PROJECT_ENV-game-record-cache-000001"; ELK_GRPCBRIDGE_TEMPLATE="_template/agocean-$PROJECT_ENV-geme-record-cache"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_GRPCBRIDGE_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_GRPCBRIDGE_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-game-record-cache": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 150,"index_patterns" : ["agocean-'$PROJECT_ENV'-game-record-cache-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-game-record-cache"}}}'; ### template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_GRPCBRIDGE_TEMPLATE response"; ### index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_GRPCBRIDGE_INDEX response"; #event ELK_GRPCBRIDGE_INDEX="agocean-$PROJECT_ENV-game-record-cache-event-000001"; ELK_GRPCBRIDGE_TEMPLATE="_template/agocean-$PROJECT_ENV-game-record-cache-event"; ELASTICSEARCH_HOST_INDEX="$ELASTICSEARCH_HOST""$ELK_GRPCBRIDGE_INDEX"; ELASTICSEARCH_HOST_TEMPLATE="$ELASTICSEARCH_HOST""$ELK_GRPCBRIDGE_TEMPLATE"; INDEX_DATA='{"aliases": {"agocean-'$PROJECT_ENV'-game-record-cache-event": {"is_write_index": true}}}'; TEMPLATE_DATA='{"order" : 200,"index_patterns" : ["agocean-'$PROJECT_ENV'-game-record-cache-event-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-game-record-cache-event"}}}'; ### template curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$TEMPLATE_DATA" \ $ELASTICSEARCH_HOST_TEMPLATE echo " $ELK_GRPCBRIDGE_TEMPLATE response"; ### index curl \ --silent \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data "$INDEX_DATA" \ $ELASTICSEARCH_HOST_INDEX echo " $ELK_GRPCBRIDGE_INDEX response"; #---------------------------------------------------------------初始化遊戲工作室 index---------------------------------------------------------- for index in $(jq 'keys | .[]' <<< $GAME_STUDIOS); do # deleteResponseTxt; rm -f $TMP_RESPNOSE_FILE; CONFIG=$(jq -r ".[$index]" <<< $GAME_STUDIOS); GAMESTUDIONAME=$(jq -r '.gameStudio' <<< $CONFIG); ELASTICSEARCH_HOST_COMMON_TEMPLATE="$ELASTICSEARCH_HOST"_template/agocean-"$PROJECT_ENV"-game-"$GAMESTUDIONAME"; ELASTICSEARCH_HOST_COMMON="$ELASTICSEARCH_HOST"agocean-"$PROJECT_ENV"-game-"$GAMESTUDIONAME"-000001; ELASTICSEARCH_HOST_EVENT_TEMPLATE="$ELASTICSEARCH_HOST"_template/agocean-"$PROJECT_ENV"-game-event-"$GAMESTUDIONAME"; ELASTICSEARCH_HOST_EVENT="$ELASTICSEARCH_HOST"agocean-"$PROJECT_ENV"-game-event-"$GAMESTUDIONAME"-000001; # objectString="$ROITING_TYPE/$ROUTING_PATH@$BRIDGE_PATH"; printf '\n'; echo "===============start" echo "registry count $index: $GAMESTUDIONAME"; echo "full index api: $ELASTICSEARCH_HOST_FULL"; printf '\n'; # https://curl.se/docs/manpage.html ## common studio template CODE=$(curl \ --silent \ --output $TMP_RESPNOSE_FILE \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data '{"order" : 150,"index_patterns" : ["agocean-'$PROJECT_ENV'-game-'$GAMESTUDIONAME'-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-game-'$GAMESTUDIONAME'"}},"mappings":{"properties": {"s_p":{"properties":{"detail":{"type":"flattened"},"meta":{"type":"flattened"},"result":{"type":"flattened"},"input":{"type":"flattened"},"output":{"type":"flattened"}}}}}}' \ $ELASTICSEARCH_HOST_COMMON_TEMPLATE) ## common studio index CODE=$(curl \ --silent \ --output $TMP_RESPNOSE_FILE \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data '{"aliases": {"agocean-'$PROJECT_ENV'-game-'$GAMESTUDIONAME'": {"is_write_index": true}}}' \ $ELASTICSEARCH_HOST_COMMON) # echo "vvvvvvvv"; # echo "wtf$CODE"; # echo "^^^^^^^^"; if ! [[ "$CODE" =~ ^2 ]]; then echo "HTTP_CODE: $CODE"; PATTERN_OBJECT_EXIST="resource_already_exists_exception"; if grep -q "$PATTERN_OBJECT_EXIST" $TMP_RESPNOSE_FILE then echo "RESPONSE: $(grep "$PATTERN_OBJECT_EXIST" response.txt)"; code if found else cat response.txt printf "\n"; echo "FATAL ERROR, EXIT REGISTRY." exit 1; # code if not found fi else echo "add $GAMESTUDIONAME success." fi ## event studio template CODE=$(curl \ --silent \ --output $TMP_RESPNOSE_FILE \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data '{"order" : 150,"index_patterns" : ["agocean-'$PROJECT_ENV'-game-event-'$GAMESTUDIONAME'-*"],"settings": {"index": {"lifecycle.rollover_alias": "agocean-'$PROJECT_ENV'-game-event-'$GAMESTUDIONAME'"}},"mappings":{"properties": {"s_p":{"properties":{"detail":{"type":"flattened"},"meta":{"type":"flattened"},"result":{"type":"flattened"},"input":{"type":"flattened"},"output":{"type":"flattened"}}}}}}' \ $ELASTICSEARCH_HOST_EVENT_TEMPLATE) ## event studio index CODE=$(curl \ --silent \ --output $TMP_RESPNOSE_FILE \ --write-out %{http_code} \ --user $ELASTIC_USER:$ELASTIC_TOKEN \ --request PUT \ --header "Content-Type: application/json" \ --data '{"aliases": {"agocean-'$PROJECT_ENV'-game-event-'$GAMESTUDIONAME'": {"is_write_index": true}}}' \ $ELASTICSEARCH_HOST_EVENT) # echo "vvvvvvvv"; # echo "wtf$CODE"; # echo "^^^^^^^^"; if ! [[ "$CODE" =~ ^2 ]]; then echo "HTTP_CODE: $CODE"; PATTERN_OBJECT_EXIST="resource_already_exists_exception"; if grep -q "$PATTERN_OBJECT_EXIST" $TMP_RESPNOSE_FILE then echo "RESPONSE: $(grep "$PATTERN_OBJECT_EXIST" response.txt)"; code if found else cat response.txt printf "\n"; echo "FATAL ERROR, EXIT REGISTRY." exit 1; # code if not found fi else echo "add $GAMESTUDIONAME success." fi echo "===============" done # deleteResponseTxt; rm -f $TMP_RESPNOSE_FILE; printf "\n"; echo "JOB FINISHED." exit 0; ```