添加indexmaping
parent
c427e1d32c
commit
8657f73f35
|
@ -6,8 +6,6 @@ import (
|
||||||
"gopkg.in/olivere/elastic.v3"
|
"gopkg.in/olivere/elastic.v3"
|
||||||
"qiniupkg.com/x/log.v7"
|
"qiniupkg.com/x/log.v7"
|
||||||
"reflect"
|
"reflect"
|
||||||
"context"
|
|
||||||
|
|
||||||
)
|
)
|
||||||
const(
|
const(
|
||||||
ERROR_PTR = "nullpointer error"
|
ERROR_PTR = "nullpointer error"
|
||||||
|
@ -106,10 +104,6 @@ func (p *ElkEngine)Update(index string,types string,id string,data map[string]in
|
||||||
// 创建 elasticSearch 的 Mapping
|
// 创建 elasticSearch 的 Mapping
|
||||||
func (p *ElkEngine)InitMapping(esIndexName string, esTypeName string, typeMapping string) error{
|
func (p *ElkEngine)InitMapping(esIndexName string, esTypeName string, typeMapping string) error{
|
||||||
var err 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()
|
exists, err := p.cli.IndexExists(esIndexName).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("IndexExists" + err.Error())
|
log.Println("IndexExists" + err.Error())
|
||||||
|
@ -122,7 +116,7 @@ func (p *ElkEngine)InitMapping(esIndexName string, esTypeName string, typeMappin
|
||||||
if !exists {
|
if !exists {
|
||||||
log.Println("es index not exists: " + esIndexName)
|
log.Println("es index not exists: " + esIndexName)
|
||||||
// Create a new index.
|
// 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 {
|
if err != nil {
|
||||||
log.Println("CreateIndex" + err.Error())
|
log.Println("CreateIndex" + err.Error())
|
||||||
return err
|
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")
|
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
|
return err
|
||||||
}
|
}
|
Loading…
Reference in New Issue