Skip to content

Commit

Permalink
Merge pull request #2 from felipejfc/master
Browse files Browse the repository at this point in the history
make history index pattern configurable
  • Loading branch information
felipejfc authored Oct 24, 2017
2 parents 5ad81ad + 872987c commit e7faa86
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type App struct {
Engine engine.Server
RedisClient *redisclient.RedisClient
NewRelic newrelic.Application
HistoryIndexPattern string
}

// GetApp creates an app given the parameters
Expand Down Expand Up @@ -97,6 +98,7 @@ func (app *App) configureSentry() {

func (app *App) configureApplication() {
app.Engine = standard.New(fmt.Sprintf("%s:%d", app.Host, app.Port))
app.HistoryIndexPattern = viper.GetString("elasticsearch.indexPattern")
app.API = echo.New()
a := app.API
_, w, _ := os.Pipe()
Expand Down
2 changes: 1 addition & 1 deletion app/histories.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func HistoriesHandler(app *App) func(c echo.Context) error {

var searchResults *elastic.SearchResult
err = WithSegment("elasticsearch", c, func() error {
searchResults, err = esclient.Search().Index("chat-*").Query(boolQuery).
searchResults, err = esclient.Search().Index(app.HistoryIndexPattern).Query(boolQuery).
Sort("timestamp", false).From(from).Size(limit).Do(context.TODO())
return err
})
Expand Down
4 changes: 2 additions & 2 deletions app/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func HistoryHandler(app *App) func(c echo.Context) error {

var searchResults *elastic.SearchResult
err = WithSegment("elasticsearch", c, func() error {
searchResults, err = esclient.Search().Index("chat-*").Query(boolQuery).
searchResults, err = esclient.Search().Index(app.HistoryIndexPattern).Query(boolQuery).
Sort("timestamp", false).From(from).Size(limit).Do(context.TODO())
return err
})
Expand Down Expand Up @@ -129,7 +129,7 @@ func HistorySinceHandler(app *App) func(c echo.Context) error {

var searchResults *elastic.SearchResult
err = WithSegment("elasticsearch", c, func() error {
searchResults, err = esclient.Search().Index("chat-*").Query(boolQuery).
searchResults, err = esclient.Search().Index(app.HistoryIndexPattern).Query(boolQuery).
Sort("timestamp", false).From(from).Size(limit).Pretty(true).Do(context.TODO())
return err
})
Expand Down
1 change: 1 addition & 0 deletions config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ healthcheck:
elasticsearch:
host: "http://localhost:9123"
sniff: false
indexPattern: "chat-*"
indexMappings:
chat: '{ "mappings": { "message":{}}}'
redis:
Expand Down
1 change: 1 addition & 0 deletions config/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ healthcheck:
elasticsearch:
host: "http://localhost:9123"
sniff: false
indexPattern: "chat-*"
indexMappings:
chat: '{ "mappings": { "message":{}}}'
redis:
Expand Down

0 comments on commit e7faa86

Please sign in to comment.