Go实战全家桶之六:goweb微服务框架和工具,GOWEB通过db-table生成es-index

代码:https://gitee.com/ichub/goweb.git

位置:

通过表元数据生成es mappings定义

执行func (this *TestDb2esMetaSuite) Test002_makeIndexFromTable() {

    FindBeanDb2esMetafactroy().MakeDb2Es("sys_user")

}结果

2024-06-22 21:13:02.779 [INFO] {
     "settings": "  { \n  }",
     "mappings": "{\n     \"mappings\": {\n          \"properties\": {\n               \n          }\n     }\n}"
}

通过DB生成ES index数据

func (this *TestDb2cmdRequestSuite) Test010_Sync2EsEmp() {
    this.tablename = "employee"

    this.inst.CreateIndexDb2Es(this.tablename)
    this.inst.SyncDb2Es(this.tablename)

}

查询employee_es

func (this *TestDb2cmdRequestSuite) Test009_QueryEs() {
    this.inst.tablename = "employee"
    this.queryRequest.IndexName = this.inst.Table2IndexName()
    this.queryRequest.PageSize = 2
    this.queryRequest.EsMust().EsTerm("code", "00000002")
    this.queryRequest.EsTerm("contract_term", 3).EsTerm("id", 1352)
    var result, err = this.queryRequest.Query()
    if err != nil {
       logrus.Error(err)
       return
    }
    logrus.Info(result)
    this.Equal(200, result.Code)
}

查询结果:

INFO[2024-06-622 21:19:24]D:/go-ichub/go/goweb/common/pagemsg/pagereq/db2cmd/db2cmd_request_suite_test.go:122 gitee.com/ichub/goweb/common/pagemsg/pagereq/db2cmd.(*TestDb2cmdRequestSuite).Test009_QueryEs() {
     "code": 200,
     "msg": "成功",
     "page_size": 2,
     "current": 1,
     "total": 1,
     "data": [
          {
               "begin_contract": "2015-06-09T00:00:00+08:00",
               "id": 1352,
               "job_level_id": 12,
               "birthday": "1989-02-01T00:00:00+08:00",
               "wedlock": "已婚",
               "work_age": 0,
               "end_contract": "2018-06-08T00:00:00+08:00",
               "gender": "女",
               "nation_id": 1,
               "contract_term": 3,
               "politic_id": 1,
               "specialty": "市场营销",
               "address": "海南省海口市美兰区",
               "school": "武汉大学",
               "work_id": "00000002",
               "work_state": "在职",
               "conversion_time": "0001-01-01T00:00:00Z",
               "email": "chenjing@qq.com",
               "engage_form": "劳动合同",
               "name": "陈静",
               "phone": "18795556693",
               "pos_id": 30,
               "tiptop_degree": "高中",
               "begin_date": "2015-06-09T00:00:00+08:00",
               "code": "00000002",
               "department_id": 82,
               "id_card": "421288198902011234",
               "native_place": "海南",
               "not_wok_date": "0001-01-01T00:00:00Z"
          }
     ]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leijmdas

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值