添加indexmaping

master
a7458969 2020-03-25 12:52:46 +08:00
parent c427e1d32c
commit 8657f73f35
1 changed files with 1 additions and 29 deletions

View File

@ -6,8 +6,6 @@ import (
"gopkg.in/olivere/elastic.v3"
"qiniupkg.com/x/log.v7"
"reflect"
"context"
)
const(
ERROR_PTR = "nullpointer error"
@ -106,10 +104,6 @@ func (p *ElkEngine)Update(index string,types string,id string,data map[string]in
// 创建 elasticSearch 的 Mapping
func (p *ElkEngine)InitMapping(esIndexName string, esTypeName string, typeMapping string) error{
var err error
indexMapping := helper.GetEsIndexMapping()
//ctx := context.Background()
// Use the IndexExists service to check if a specified index exists.
exists, err := p.cli.IndexExists(esIndexName).Do()
if err != nil {
log.Println("IndexExists" + err.Error())
@ -122,7 +116,7 @@ func (p *ElkEngine)InitMapping(esIndexName string, esTypeName string, typeMappin
if !exists {
log.Println("es index not exists: " + esIndexName)
// Create a new index.
createIndex, err := p.cli.CreateIndex(esIndexName).Body(indexMapping).Do()
createIndex, err := p.cli.CreateIndex(esIndexName).Body(typeMapping).Do()
if err != nil {
log.Println("CreateIndex" + err.Error())
return err
@ -156,28 +150,6 @@ func (p *ElkEngine)InitMapping(esIndexName string, esTypeName string, typeMappin
return errors.New("create mapping fail, esIndexName:" + esIndexName + ", esTypeName:" + esTypeName + ", not Ack nowledged")
}
// 插入数据
/*
type WholeBrowserData struct {
BrowserId string `json:"browser_id"`
BrowserName string `json:"browser_name"`
}
// Index a tweet (using JSON serialization)
wholeBrowserData := WholeBrowserData{BrowserId: "BrowserId", BrowserName: "BrowserName" }
put1, err := client.Index().
Index(esIndexName).
Type(esTypeName).
Id("1").
BodyJson(wholeBrowserData).
Do(ctx)
if err != nil {
// Handle error
panic(err)
}
log.Printf("Indexed tweet %s to index %s, type %s\n", put1.Id, put1.Index, put1.Type)
*/
return err
}