@@ -86,7 +86,7 @@ func reindex(ctx context.Context, sourceIndex string, config *reindexConfig, wai
8686 // If mappings are not passed, we fetch the mappings of the old index.
8787 if config .Mappings == nil {
8888 found := util .IsExists (Mappings .String (), config .Action )
89- if config .Action == nil || found {
89+ if len ( config .Action ) == 0 || found {
9090 config .Mappings , err = mappingsOf (ctx , sourceIndex )
9191 if err != nil {
9292 return nil , fmt .Errorf (`error fetching mappings of index "%s": %v` , sourceIndex , err )
@@ -97,7 +97,7 @@ func reindex(ctx context.Context, sourceIndex string, config *reindexConfig, wai
9797 // If settings are not passed, we fetch the settings of the old index.
9898 if config .Settings == nil {
9999 found := util .IsExists (Settings .String (), config .Action )
100- if config .Action == nil || found {
100+ if len ( config .Action ) == 0 || found {
101101 config .Settings , err = settingsOf (ctx , sourceIndex )
102102 if err != nil {
103103 return nil , fmt .Errorf (`error fetching settings of index "%s": %v` , sourceIndex , err )
@@ -132,10 +132,32 @@ func reindex(ctx context.Context, sourceIndex string, config *reindexConfig, wai
132132 return nil , err
133133 }
134134
135+ /* Copy search relevancy settings if
136+ - `search_relevancy_settings` object is present
137+ - and action array has the `search_relevancy` action defined
138+ */
139+ if config .SearchRelevancySettings != nil && util .IsExists (SearchRelevancy .String (), config .Action ) {
140+ // Index a document in .searchrelevancy index for the destination `index`
141+ err := putSearchRelevancySettings (ctx , newIndexName , * config .SearchRelevancySettings )
142+ if err != nil {
143+ return nil , fmt .Errorf (`error while copying search relevancy settings: %v` , err )
144+ }
145+ }
146+
147+ /* Copy Synonyms if `synonyms` action is set in the action array
148+ */
149+ if util .IsExists (Synonyms .String (), config .Action ) {
150+ // Update synonyms by query
151+ err := updateSynonyms (ctx , sourceIndex , newIndexName )
152+ if err != nil {
153+ return nil , fmt .Errorf (`error while updating the synonyms: %v` , err )
154+ }
155+ }
156+
135157 found := util .IsExists (Data .String (), config .Action )
136158
137159 // do not copy data
138- if ! (config .Action == nil || found ) {
160+ if ! (len ( config .Action ) == 0 || found ) {
139161 return nil , nil
140162 }
141163
@@ -479,3 +501,42 @@ func asyncReIndex(taskID, source, destination string, operation ReIndexOperation
479501 }
480502 }
481503}
504+
505+ func putSearchRelevancySettings (ctx context.Context , docID string , record map [string ]interface {}) error {
506+ _ , err := util .GetClient7 ().
507+ Index ().
508+ Refresh ("wait_for" ).
509+ Index (getSearchRelevancyIndex ()).
510+ BodyJson (record ).
511+ Id (docID ).
512+ Do (ctx )
513+ if err != nil {
514+ log .Errorln (logTag , ": error indexing searchrelevancy record for id=" , docID , ":" , err )
515+ return err
516+ }
517+ return nil
518+ }
519+
520+ func updateSynonyms (ctx context.Context , sourceIndex string , destinationIndex string ) error {
521+ script := `
522+ if(ctx._source.index == null) {
523+ ctx._source.index = []
524+ }
525+ if(ctx._source.index instanceof String) {
526+ ctx._source.index = [ctx._source.index]
527+ }
528+ if (params.index != null) {
529+ if (ctx._source.index.indexOf(params.index) == -1) {
530+ ctx._source.index.add(params.index)
531+ }
532+ }`
533+ params := map [string ]interface {}{
534+ "index" : destinationIndex ,
535+ }
536+ switch util .GetVersion () {
537+ case 6 :
538+ return updateSynonymsEs6 (ctx , script , sourceIndex , params )
539+ default :
540+ return updateSynonymsEs7 (ctx , script , sourceIndex , params )
541+ }
542+ }
0 commit comments