package logic import ( "context" "fmt" "demo/internal/svc" "demo/internal/types" es "demo/model/es_dev" "github.com/zeromicro/go-zero/core/logx" ) type EsProFromJavaSearchDistrictLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewEsProFromJavaSearchDistrictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EsProFromJavaSearchDistrictLogic { return &EsProFromJavaSearchDistrictLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *EsProFromJavaSearchDistrictLogic) EsProFromJavaSearchDistrict(req *types.EsProQueryName) (resp *types.Response, err error) { // es 查询语句 esQuery := ` { "query": { "bool":{ "must":[ { "bool": { "must": [ {"match": { "districtName": "%s" } }, {"term": { "districtCode": "%s" } }, {"term": { "year": "%s" } }, {"term": { "lotType":"%s" } } ], "must_not": [ { "bool": { "must":[ { "bool": { "should":[ {"term": { "schoolId":"" } }, {"bool": { "mustNot": [ { "exists": { "field": "schoolId" } } ] } } ] } }, { "bool": { "should":[ {"term": { "schoolName":"" } }, {"bool": { "mustNot": [ { "exists": { "field": "schoolName" } } ] } } ] } } ] } } ] } } ] } } } ` // es 查询 esQueryStr := fmt.Sprintf(esQuery, req.Name, req.Code, req.Year, req.LotType) doc, err := es.EsServiceApp.EsSearchDocWithStrAndIndex(l.ctx, esQueryStr, int(req.Page), int(req.Size), "thoroughly_districts_xw") if err != nil { return nil, err } return &types.Response{ Success: true, Message: "success", Result: doc, }, nil }