ZincSearch 环境搭建

Joe's blog / 2023-08-11 / 原文

使用模式

ZincSearch 中存储需要查询和展示的关键信息,数据的详细信息使用 mysql存储

如何和Mysql 保持一致: 每5分钟将变更的数据批量推送到mq ,由mq来更新es中的数据,比每次数据变化就发送给下游,效率高很多

1. 创建索引

POST http://localhost:4080/api/index

注意: index 设置为false 将无法用于查询和过滤

{
    "name": "audit_log",
    "storage_type": "disk",
    "shard_num": 3,
    "mappings": {
        "properties": {
            "user_name": {
                "type": "text",
                "index": true,
                "store": true,
                "highlightable": false
            },
            "description": {
                "type": "text",
                "index": true,
                "store": true,
                "highlightable": true
            },
            "operation_type": {
                "type": "numeric",
                "index": false,
                "sortable": false,
                "aggregatable": true
            },
            "module": {
                "type": "numeric",
                "index": false,
                "sortable": false,
                "aggregatable": true
            },
            "create_time": {
                "type": "date",
                "format": "2006-01-02 15:04:05",
                "index": true,
                "sortable": true,
                "aggregatable": true
            }
        }
    }
}

2. 使用bulk API 导入数据

先将mysql 数据导出csv格式,

然后使用python 脚本转为ndjson格式,

将ndjson文件上传至服务器

curl http://localhost:4080/api/_bulk -i -u admin:Complexpass#123  --data-binary "@audit_log.ndjson"

ndjson数据格式

{"index": {"_index": "audit_log", "_id": "2228975"}}
{"user_name": "test", "description": "通过条件[文件名: pvs-46; 是否通过文件名排序: false; 是否通过id升序: false; 当前页数: 1; 分页大小: 15; ]查询了内容", "operation_type": 0, "module": 0, "create_time": "2023-08-09 16:32:46"}
{"index": {"_index": "audit_log", "_id": "2228976"}}
{"user_name": "tets", "description": "通过条件[文件名: pvs_46; 是否通过文件名排序: false; 是否通过id升序: false; 当前页数: 1; 分页大小: 15; ]查询了内容", "operation_type": 0, "module": 0, "create_time": "2023-08-09 16:32:54"}

坑: 接口返回数据并未完全导入成功,需要等待一会,目前测试一次导入70W条数据没有问题v