Skip to content

Commit

Permalink
Added support for setting fresh_interval for elasticsearch template
Browse files Browse the repository at this point in the history
  • Loading branch information
BenB196 committed Sep 24, 2019
1 parent 2526b30 commit ce2cdcf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ Currently, only JSON formatted configuration files are accepted, in the future Y
"indexTimeGen": "onOrBefore", #How to determine what time to use for the time stamp. Supports timeNow, onOrBefore, eventTimestamp, or insertionTimestamp.
"elasticUrl": "http://elasticsearch:9200", #The elasticsearch URL
"sniffing": false, #This determines whether the application will automatically try update its elasticsearch node list
"bestCompression": false, #This allows for indexes to be created with best_compression codec enabled
"bestCompression": false, #This allows for indexes to be created with best_compression codec enabled
"refreshInterval": 30, #This allows you to set the refresh interval (in seconds) of the index template. If empty it disables refresh interval
"basicAuth": { #If you are using basic auth with elasticsearch
"user": "",
"password": ""
Expand Down
1 change: 1 addition & 0 deletions config/configReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Elasticsearch struct {
BasicAuth BasicAuth `json:"basicAuth,omitempty"`
Sniffing bool `json:"sniffing,omitempty"`
BestCompression bool `json:"bestCompression,omitempty"`
RefreshInterval int `json:"refreshInterval,omitempty"`
Aliases []string `json:"aliases,omitempty"`
}

Expand Down
8 changes: 8 additions & 0 deletions elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,17 @@ func BuildIndexPattern(elasticConfig config.Elasticsearch) string {
codec = ""
}

var refreshInterval string
if elasticConfig.RefreshInterval == 0 {
refreshInterval = "-1"
} else {
refreshInterval = strconv.Itoa(elasticConfig.RefreshInterval) + "s"
}

index := "{" +
" \"settings\": {" +
codec +
" \"refresh_interval\": \"" + refreshInterval + "\"," +
" \"number_of_shards\": " + strconv.Itoa(elasticConfig.NumberOfShards) + "," +
" \"number_of_replicas\": " + strconv.Itoa(elasticConfig.NumberOfReplicas) + "" +
" }," +
Expand Down

0 comments on commit ce2cdcf

Please sign in to comment.