创建全文搜索客户端
(configElasticSearch ...ElasticSearchClient)
| 104 | |
| 105 | //创建全文搜索客户端 |
| 106 | func NewElasticSearchClient(configElasticSearch ...ElasticSearchClient) (client *ElasticSearchClient) { |
| 107 | if len(configElasticSearch) > 0 { |
| 108 | client = &configElasticSearch[0] |
| 109 | } |
| 110 | //并未设置超时配置项 |
| 111 | timeout := helper.GetConfigInt64(ConfigCateElasticSearch, "timeout") |
| 112 | if timeout <= 0 { //默认超时时间为10秒 |
| 113 | timeout = 10 |
| 114 | } |
| 115 | client = &ElasticSearchClient{ |
| 116 | Host: helper.GetConfig(ConfigCateElasticSearch, "host", "http://localhost:9200/"), |
| 117 | Index: helper.GetConfig(ConfigCateElasticSearch, "index", "dochub"), |
| 118 | Type: "fulltext", |
| 119 | On: helper.GetConfigBool(ConfigCateElasticSearch, "on"), |
| 120 | Timeout: time.Duration(timeout) * time.Second, |
| 121 | } |
| 122 | client.Host = strings.TrimRight(client.Host, "/") + "/" |
| 123 | return |
| 124 | } |
| 125 | |
| 126 | //初始化全文搜索客户端,包括检查索引是否存在,mapping设置等 |
| 127 | func (this *ElasticSearchClient) Init() (err error) { |
no outgoing calls
no test coverage detected