#!/bin/bash

set -x

while [[ "$(curl -s -o /dev/null -w '%{http_code}' es-service:9200)" != "200" ]]; do sleep 1; done

ES_URL="es-service:9200/"
JSON_HEADER="Content-Type: application/json"

function put_es_with_retry() {
  wait=0
  timeout_msg="timeout_msg"
  while [ -n "$timeout_msg" ] && [ $wait -le 3 ]; do
    timeout_msg=$(curl -s -X PUT $ES_URL$1 -H "$JSON_HEADER" -d "$2" | grep "process_cluster_event_timeout_exception")

    if [ -n "$timeout_msg" ]; then
      wait=$((wait + 1))
      sleep 300
    fi
  done
}

function put_es() {
  curl -X PUT $ES_URL$1 -H "$JSON_HEADER" -d "$2"
}

# es初始启动几分钟内，请求创建index可能会失败，process_cluster_event_timeout_exception；第一个请求检查一下。
put_es_with_retry "app_block_log" '
{
  "mappings": {
    "properties": {
      "tenant_id": {
        "type": "short"
      },
      "domain_id": {
        "type": "short"
      },
      "ip": {
          "type": "ip"
      },
      "user_id": {
        "type": "long"
      },
      "user_name": {
        "type": "keyword"
      },
      "user_avatar": {
        "type": "keyword"
      },
      "process_name": {
        "type": "keyword"
      },
      "process_path": {
        "type": "keyword"
      },
      "md5": {
        "type": "keyword"
      },
      "device_uuid": {
        "type": "keyword"
      },
      "device_name": {
        "type": "keyword"
      },
      "timestamp": {
        "type": "long"
      },
      "access_mode": {
        "type": "byte"
      }
    }
  }
}
'

put_es "network_log" '
{
  "settings": {
    "analysis": {
      "analyzer": {
        "keyword_lowercase": {
          "tokenizer": "keyword",
          "filter": [ "lowercase" ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "tenant_id": {
        "type": "short"
      },
      "user_id": {
        "type": "long"
      },
      "user_name": {
        "type": "keyword"
      },
      "uuid": {
        "type": "keyword"
      },
      "security_space_name": {
        "type": "keyword"
      },
      "domain_id": {
        "type": "integer"
      },
      "local_ip": {
        "type": "ip"
      },
      "process_name": {
        "type": "keyword",
        "fields": {
          "suggest": {
            "type": "completion",
            "analyzer": "keyword_lowercase"
          }
        }
      },
      "target_address": {
        "type": "text"
      },
      "target_port": {
        "type": "integer"
      },
      "timestamp": {
        "type": "long"
      },
      "target_address_key": {
        "type": "keyword",
        "fields": {
          "suggest": {
            "type": "completion",
            "analyzer": "keyword_lowercase"
          }
        }
      },
      "target_time": {
        "type": "date"
      },
      "reason": {
        "type": "keyword"
      },
      "result": {
        "type": "boolean"
      },
      "access_type": {
        "type": "integer"
      }
    }
  }
}
'

put_es "data_delivery_log" '
{
  "mappings": {
    "properties": {
      "tenant_id": {
        "type": "short"
      },
      "data": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "data_id": {
        "type": "long"
      },
      "delivery_type": {
        "type": "long"
      },
      "dest_user_id": {
        "type": "long"
      },
      "destination": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "dev_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "dev_uuid": {
        "type": "keyword"
      },
      "display_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "domain_id": {
        "type": "long"
      },
      "security_domain": {
        "type": "keyword"
      },
      "share_id": {
        "type": "long"
      },
      "timestamp": {
        "type": "long"
      },
      "user_id": {
        "type": "long"
      },
      "user_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "user_avatar": {
        "type": "keyword"
      },
      "ip": {
        "type": "keyword"
      },
      "is_folder": {
        "type": "boolean"
      },
      "file_size": {
        "type": "long"
      },
      "file_sha256": {
        "type": "keyword"
      },
      "action": {
        "type": "byte"
      },
      "success": {
        "type": "boolean"
      },
      "file_count": {
        "type": "integer"
      },
      "warning_reason": {
        "type": "keyword"
      },
      "reject_reason": {
        "type": "keyword"
      },
      "is_warning": {
        "type": "boolean"
      },
      "is_rejected": {
        "type": "boolean"
      },
      "application_id": {
        "type": "long"
      },
      "access_mode": {
        "type": "byte"
      },
      "device_type": {
        "type": "byte"
      },
      "is_domain_interior": {
        "type": "boolean"
      },
      "file_sha256s": {
        "type": "keyword"
      },
      "process_name": {
        "type": "keyword"
      },
      "process_hash": {
        "type": "keyword"
      },
      "destination_address": {
        "type": "keyword"
      }
    }
  }
}
'

put_es "operation_log" '
{
  "mappings" : {
    "properties" : {
      "tenant_id": {
        "type": "short"
      },
      "detail" : {
        "type" : "text"
      },
      "op_time" : {
        "type" : "long"
      },
      "op_type" : {
        "type" : "long"
      },
      "operator_id" : {
        "type" : "long"
      },
      "operator_ip" : {
        "type" : "keyword"
      },
      "operator_name" : {
        "type" : "keyword"
      }
    }
  }
}
'

put_es "device_detail_info" '
{
  "mappings" : {
    "properties" : {
      "dev_uuid" : {
        "type" : "keyword"
      },
      "update_time" : {
        "type" : "long"
      },
      "antivirus": {
        "type": "text",
        "index": false
      },
      "patch": {
        "type": "text",
        "index": false
      },
      "software": {
        "type": "text",
        "index": false
      },
      "system_status": {
        "type": "text",
        "index": false
      },
      "process": {
        "type": "text",
        "index": false
      },
      "service": {
        "type": "text",
        "index": false
      },
      "network": {
        "type": "text",
        "index": false
      },
      "startup": {
        "type": "text",
        "index": false
      }
    }
  }
}'

put_es "rule_file_op_log" '
{
  "mappings": {
    "properties": {
      "share_id": {
        "type": "long"
      },
      "share_log_id": {
        "type": "keyword"
      },
      "timestamp": {
        "type": "long"
      },
      "user_id": {
        "type": "long"
      },
      "user_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "log_type": {
        "type": "long"
      },
      "content": {
        "type": "text",
        "index": false
      }
    }
  }
}
'

put_es "delete_domain_user_data_log" '
{
  "mappings" : {
    "properties" : {
      "tenant_id": {
        "type": "short"
      },
      "domain_id" : {
        "type" : "short"
      },
      "user_id" : {
        "type" : "long"
      },
      "user_name" : {
        "type" : "text"
      },
      "delete_status" : {
        "type" : "text"
      },
      "timestamp" : {
        "type" : "long"
      },
      "detail" : {
        "type" : "object"
      }
    }
  }
}
'

put_es "delete_user_data_status_log" '
{
  "mappings" : {
    "properties" : {
      "tenant_id": {
          "type": "short"
      },
      "domain_id" : {
        "type" : "short"
      },
      "user_id" : {
        "type" : "long"
      },
      "device_uuid" : {
        "type" : "text"
      },
      "deleted" : {
        "type" : "boolean"
      },
      "timestamp" : {
        "type" : "long"
      }
    }
  }
}
'

put_es "dynamic_auth_log" '
{
    "mappings": {
        "properties": {
            "ip": {
                "type": "ip"
            },
            "user_id": {
                "type": "long"
            },
            "device_uuid": {
                "type": "keyword"
            },
            "reason": {
                "type": "integer"
            },
            "msg": {
                "type": "text"
            },
            "handle_type": {
                "type": "integer"
            },
            "handle_score": {
                "type": "integer"
            },
            "timestamp": {
                "type": "long"
            },
            "tenant_id": {
                "type": "short"
            }
        }
    }
}
'

put_es "client_auth_log" '
{
    "mappings": {
        "properties": {
            "user_id": {
                "type": "long"
            },
            "user_name": {
                "type": "keyword"
            },
            "device_uuid": {
                "type": "keyword"
            },
            "ip": {
                "type": "ip"
            },
            "result": {
                "type": "boolean"
            },
            "msg": {
                "type": "text"
            },
            "timestamp": {
                "type": "long"
            },
            "tenant_id": {
                "type": "short"
            },
            "access_mode": {
              "type": "byte"
            }
        }
    }
}
'

put_es "clipboard_log" '
{
  "mappings" : {
    "properties" : {
      "tenant_id" : {
        "type" : "short"
      },
      "domain_id" : {
        "type" : "short"
      },
      "ip": {
          "type": "ip"
      },
      "direction" : {
        "type" : "byte"
      },
      "user_id" : {
        "type" : "long"
      },
      "user_name" : {
        "type" : "keyword"
      },
      "user_avatar" : {
        "type" : "keyword",
        "index": false
      },
      "device_uuid" : {
        "type" : "keyword"
      },
      "device_name" : {
        "type" : "keyword"
      },
      "is_rejected" : {
        "type" : "boolean"
      },
      "data_type" : {
        "type" : "byte"
      },
      "content" : {
        "type" : "keyword",
        "index": false
      },
      "image_ext" : {
        "type" : "keyword"
      },
      "timestamp" : {
        "type" : "long"
      },
      "access_mode": {
        "type": "byte"
      }
    }
  }
}
'

put_es "client_integrity_exception_log" '
{
    "mappings": {
        "properties": {
            "tenant_id": {
                "type": "short"
            },
            "device_uuid": {
                "type": "keyword"
            },
            "ip": {
                "type": "ip"
            },
            "timestamp": {
                "type": "long"
            },
            "version": {
                "type": "keyword"
            },
            "type": {
                "type": "integer"
            },
            "content": {
                "type": "text"
            },
            "action": {
                "type": "integer"
            },
            "file_sha256": {
                "type": "keyword"
            },
            "file_name": {
                "type": "keyword"
            },
            "file_size": {
                "type": "long"
            }
        }
    }
}
'

put_es "client_process_protect_log" '
{
    "mappings": {
        "properties": {
            "tenant_id": {
                "type": "short"
            },
            "device_uuid": {
                "type": "keyword"
            },
            "ip": {
                "type": "ip"
            },
            "timestamp": {
                "type": "long"
            },
            "version": {
                "type": "keyword"
            },
            "protect_process_name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            },
            "reject_process_name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            },
            "username": {
                "type": "keyword"
            },
            "action": {
                "type": "integer"
            },
            "success": {
                "type": "boolean"
            }
        }
    }
}
'

put_es "client_install_directory_protect_log" '
{
    "mappings": {
        "properties": {
            "tenant_id": {
                "type": "short"
            },
            "device_uuid": {
                "type": "keyword"
            },
            "ip": {
                "type": "ip"
            },
            "timestamp": {
                "type": "long"
            },
            "version": {
                "type": "keyword"
            },
            "process_name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            },
            "username": {
                "type": "keyword"
            },
            "action": {
                "type": "integer"
            },
            "path": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            },
            "success": {
                "type": "boolean"
            }
        }
    }
}
'

put_es "client_registry_protect_log" '
{
    "mappings": {
        "properties": {
            "tenant_id": {
                "type": "short"
            },
            "device_uuid": {
                "type": "keyword"
            },
            "ip": {
                "type": "ip"
            },
            "timestamp": {
                "type": "long"
            },
            "version": {
                "type": "keyword"
            },
            "process_name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            },
            "username": {
                "type": "keyword"
            },
            "action": {
                "type": "integer"
            },
            "path": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            },
            "success": {
                "type": "boolean"
            }
        }
    }
}
'

put_es "gateway_flow_log" '
{
  "mappings" : {
    "properties" : {
      "tenant_id": {
        "type": "short"
      },
      "gateway_id": {
        "type": "integer"
      },
      "timestamp": {
        "type": "long"
      },
      "upstream_bytes": {
        "type": "long"
      },
      "downstream_bytes": {
        "type": "long"
      }
    }
  }
}
'

put_es "mobile_network_log" '
{
    "settings": {
      "index": {
        "number_of_replicas": 0
      }
    },
    "mappings": {
      "properties": {
        "tenant_id": {
          "type": "short"
        },
        "user_id": {
          "type": "long"
        },
        "user_name": {
          "type": "keyword"
        },
        "device_uuid": {
          "type": "keyword"
        },
        "local_ip": {
          "type": "ip"
        },
        "app_name": {
          "type": "keyword"
        },
        "timestamp": {
          "type": "long"
        },
        "address": {
          "type": "keyword"
        },
        "port": {
          "type": "short"
        },
        "reason": {
          "type": "keyword"
        }
      }
    }
}
'

put_es "mobile_data_outgoing_log" '
{
    "settings": {
      "index": {
        "number_of_replicas": 0
      }
    },
    "mappings": {
      "properties": {
        "tenant_id": {
          "type": "short"
        },
        "user_id": {
          "type": "long"
        },
        "user_name": {
          "type": "keyword"
        },
        "device_uuid": {
          "type": "keyword"
        },
        "local_ip": {
          "type": "ip"
        },
        "app_name": {
          "type": "keyword"
        },
        "timestamp": {
          "type": "long"
        },
        "result": {
          "type": "byte"
        },
        "data_type": {
          "type": "byte"
        },
        "file_name": {
          "type": "keyword",
          "index": false
        },
        "text_content": {
          "type": "keyword",
          "index": false
        },
        "image_hash": {
          "type": "keyword",
          "index": false
        }
      }
    }
}
'

put_es "_settings" '
{"index.merge.scheduler.max_thread_count" : 1}
'

put_es "_settings" '
{
  "index": {
    "number_of_replicas": "0"
  }
}
'

put_es "client_ram_protect_log" '
{
    "mappings": {
        "properties": {
            "tenant_id": {
                "type": "short"
            },
            "device_uuid": {
                "type": "keyword"
            },
            "timestamp": {
                "type": "long"
            },
            "version": {
                "type": "keyword"
            },
            "process_name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            },
            "pid": {
                "type": "integer"
            },
            "user_id": {
                "type": "integer"
            },
            "user_name": {
                "type": "keyword"
            },
            "domain_name": {
                "type": "keyword"
            },
            "action": {
                "type": "integer"
            }
        }
    }
}'

put_es "user_messages" '
{
    "settings": {
      "index": {
        "number_of_replicas": 0
      }
    },
    "mappings": {
        "properties": {
            "uid": {
                "type": "long"
            },
            "message_type": {
                "type": "short"
            },
            "message_detail_id": {
                "type": "long"
            },
            "create_time": {
                "type": "long"
            }
        }
    }
}'

put_es "app_store" '
{
    "settings": {
        "analysis": {
            "analyzer": {
                "ik_smart_pinyin": {
                    "type": "custom",
                    "tokenizer": "ik_smart",
                    "filter": [
                        "app_store_pinyin",
                        "word_delimiter"
                    ]
                },
                "ik_max_word_pinyin": {
                    "type": "custom",
                    "tokenizer": "ik_max_word",
                    "filter": [
                        "app_store_pinyin",
                        "word_delimiter"
                    ]
                }
            },
            "filter": {
                "app_store_pinyin": {
                    "type": "pinyin",
                    "keep_separate_first_letter": true,
                    "keep_full_pinyin": true,
                    "keep_original": true,
                    "limit_first_letter_length": 16,
                    "lowercase": true,
                    "remove_duplicated_term": true
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "name": {
                "type": "text",
                "analyzer": "ik_smart_pinyin",
                "search_analyzer": "ik_smart_pinyin"
            },
            "desc": {
                "type": "text",
                "analyzer": "ik_max_word_pinyin",
                "search_analyzer": "ik_smart_pinyin"
            },
            "version": {
                "type": "text",
                "analyzer": "ik_smart_pinyin",
                "search_analyzer": "ik_smart_pinyin"
            },
            "upload_time": {
                "type": "integer"
            },
            "change_time": {
                "type": "integer"
            },
            "path": {
                "type": "keyword"
            },
            "size": {
                "type": "integer"
            },
            "file_id": {
                "type": "keyword"
            },
            "app_type_id": {
                "type": "keyword"
            },
            "sha256": {
                "type": "keyword"
            },
            "repo_id": {
                "type": "keyword"
            },
            "platform": {
                "type": "integer"
            },
            "adder_id": {
                "type": "integer"
            }
        }
    }
}'


put_es "app_type" '
{
    "settings": {
        "analysis": {
            "analyzer": {
                "ik_smart_pinyin": {
                    "type": "custom",
                    "tokenizer": "ik_smart",
                    "filter": [
                        "app_store_pinyin",
                        "word_delimiter"
                    ]
                }
            },
            "filter": {
                "app_store_pinyin": {
                    "type": "pinyin",
                    "keep_separate_first_letter": true,
                    "keep_full_pinyin": true,
                    "keep_original": true,
                    "limit_first_letter_length": 16,
                    "lowercase": true,
                    "remove_duplicated_term": true
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "name": {
                "type": "text",
                "analyzer": "ik_smart_pinyin",
                "search_analyzer": "ik_smart_pinyin"
            },
            "create_time": {
                "type": "integer"
            },
            "change_time": {
                "type": "integer"
            },
            "adder_id": {
                "type": "integer"
            }
        }
    }
}'


put_es "import_file_log" '
{
  "settings": {
    "index": {
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "tenant_id": {
        "type": "short"
      },
      "device_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "device_uuid": {
        "type": "keyword"
      },
      "domain_id": {
        "type": "long"
      },
      "timestamp": {
        "type": "long"
      },
      "user_id": {
        "type": "long"
      },
      "ip": {
        "type": "keyword"
      },
      "file_name": {
        "type": "keyword"
      },
      "is_folder": {
        "type": "boolean"
      },
      "file_size": {
        "type": "long"
      },
      "file_sha256": {
        "type": "keyword"
      },
      "file_count": {
        "type": "integer"
      },
      "action": {
        "type": "byte"
      },
      "success": {
        "type": "boolean"
      },
      "approval_id": {
        "type": "long"
      }
    }
  }
}
'

put_es "osi_log" '
{
  "mappings": {
    "properties": {
      "device_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "process_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "access_url": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "origin_url": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "user_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "device_uuid": {
        "type": "keyword"
      },
      "domain_id": {
        "type": "long"
      },
      "timestamp": {
        "type": "long"
      },
      "user_id": {
        "type": "long"
      },
      "result": {
        "type": "boolean"
      },
      "interception_reason": {
        "type": "short"
      }
    }
  }
}
'

put_es "sdp_log" '
{
  "mappings": {
    "properties": {
      "user_id": {
        "type": "long"
      },
      "origin_ip": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "timestamp": {
        "type": "long"
      },
      "access_url": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "access_port": {
        "type": "long"
      },
      "access_result": {
        "type": "long"
      },
      "device_uuid": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "gateway_id": {
        "type": "long"
      }
    }
  }
}
'

put_es "domain_outside_network_log" '
{
  "mappings": {
    "properties": {
      "user_id": {
        "type": "long"
      },
      "user_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ip": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "timestamp": {
        "type": "long"
      },
      "access_url": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "access_port": {
        "type": "long"
      },
      "access_result": {
        "type": "long"
      },
      "device_uuid": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "version": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "process_name": {
        "type": "text",
        "fields": {
          "keyword": {
              "type": "keyword"
          }
        }
      }
    }
  }
}
'

put_es "users" '
{
  "settings": {
    "analysis": {
      "analyzer": {
        "ik_smart_pinyin": {
          "type": "custom",
          "tokenizer": "name_ngram",
          "filter": [
            "user_search_pinyin"
          ]
        }
      },
      "tokenizer": {
        "name_ngram": {
          "type": "ngram",
          "min_gram": 1,
          "max_gram": 20,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      },
      "filter": {
        "user_search_pinyin": {
          "type": "pinyin",
          "keep_separate_first_letter": false,
          "keep_joined_full_pinyin": true,
          "keep_full_pinyin": true,
          "keep_original": true,
          "limit_first_letter_length": 16,
          "lowercase": true,
          "remove_duplicated_term": true
        }
      }
    },
    "index": {
      "max_result_window": 114514,
      "max_ngram_diff": 20
    }
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "integer"
      },
      "user_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "display_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "title": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "email": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "mobile": {
        "type": "keyword"
      },
      "avatar": {
        "type": "keyword"
      },
      "active": {
        "type": "integer"
      },
      "local_weakly_department_id": {
        "type": "long"
      },
      "local_strongly_department_id": {
        "type": "long"
      },
      "ad_id": {
        "type": "integer"
      },
      "ad_user_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ad_display_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ad_title": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ad_email": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ad_mobile": {
        "type": "keyword"
      },
      "ad_avatar": {
        "type": "keyword"
      },
      "ad_weakly_department_id": {
        "type": "long"
      },
      "ad_strongly_department_id": {
        "type": "long"
      },
      "ldap_id": {
        "type": "integer"
      },
      "ldap_user_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ldap_display_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ldap_title": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ldap_email": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ldap_mobile": {
        "type": "keyword"
      },
      "ldap_avatar": {
        "type": "keyword"
      },
      "ldap_weakly_department_id": {
        "type": "long"
      },
      "ldap_strongly_department_id": {
        "type": "long"
      },
      "ding_id": {
        "type": "integer"
      },
      "ding_user_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ding_display_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ding_title": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ding_email": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "ding_mobile": {
        "type": "keyword"
      },
      "ding_avatar": {
        "type": "keyword"
      },
      "ding_weakly_department_id": {
        "type": "long"
      },
      "ding_strongly_department_id": {
        "type": "long"
      },
      "feishu_id": {
        "type": "integer"
      },
      "feishu_user_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "feishu_display_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "feishu_title": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "feishu_email": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "feishu_mobile": {
        "type": "keyword"
      },
      "feishu_avatar": {
        "type": "keyword"
      },
      "feishu_weakly_department_id": {
        "type": "long"
      },
      "feishu_strongly_department_id": {
        "type": "long"
      },
      "work_weixin_id": {
        "type": "integer"
      },
      "work_weixin_user_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "work_weixin_display_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "work_weixin_title": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "work_weixin_email": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "work_weixin_mobile": {
        "type": "keyword"
      },
      "work_weixin_avatar": {
        "type": "keyword"
      },
      "work_weixin_weakly_department_id": {
        "type": "long"
      },
      "work_weixin_strongly_department_id": {
        "type": "long"
      },
      "role": {
        "type": "integer"
      },
      "weakly_department_id": {
        "type": "long"
      },
      "strongly_department_id": {
        "type": "long"
      },
      "department_name": {
        "type": "text",
        "analyzer": "ik_smart_pinyin",
        "search_analyzer": "keyword",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "sso_type": {
        "type": "integer"
      },
      "path": {
        "type": "keyword"
      },
      "create_time": {
        "type": "integer"
      },
      "update_time": {
        "type": "integer"
      }
    }
  }
}'

put_es "watermark_task_log" '
{
  "settings": {
    "index": {
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "integer"
      },
      "timestamp": {
        "type": "long"
      },
      "sponsor": {
        "type": "keyword",
        "fields": {
          "wildcard": {
            "type": "wildcard"
          }
        }
      },
      "file_name": {
        "type": "keyword"
      },
      "file_size": {
        "type": "long"
      },
      "file_md5": {
        "type": "keyword"
      },
      "action": {
        "type": "byte"
      },
      "success": {
        "type": "boolean"
      }
    }
  }
}
'
