title: aliasing with spring data elasticsearch repository search and persist conflict
body: <p>i'm having aliasing conflict issues using spring-data-es,</p>
  
  <p>I have a need for daily based roll-over index - <code>A_Day1, A_Day2, ... A_now()</code> with aliasing:</p>
  
  <pre><code>1. active_A - points to latest index - A_now()
  *Persistence should be done on this alias*
  2. search_A - points to all existing indexes + A_now()
  *Search should be done on this alias*
  </code></pre>
  
  <p>My document entity holds the indexName of search_A,
  <code>@Document(indexName = "search_A", indexType="...")</code>,
  This causes every-time a search query is performed, either via repository (findBy....) or via ElasticTemplate.queryForPage(Query, Clazz.class) to search <strong>on this alias</strong> - and thus searching on all existing indexes, <strong>which works as expected.</strong>                                       </p>
  
  <p><strong>Problem arise on persistent</strong> -</p>
  
  <p>Using spring-data-es repository I persist entities in all of the documents-persist-life-cycle. </p>
  
  <p><code>repository.save(Entity)</code>,</p>
  
  <p>Spring-data-es will scan indexName and persist- meaning now persistence is to (search_A) alias <strong>and NOT to active_A alias</strong>- which <strong>does not work as expected</strong>.</p>
  
  <p>I thought of few <strong>workaround solutions</strong> which are not elegant and wasteful IMO:</p>
  
  <ol>
  <li>Override save() step in my DAO's - then before calling
  repository.save - change annotation value in runtime to persistence alias, then
  after persistence - change it again to search alias.  </li>
  <li>Change @Document(indexName=#{dynamicDailyBased()}) using spring SPEL, but then i'm still stuck with need of alias to search. as spring-data-es will need indexName for it search options. </li>
  <li>Override all
  search to happen in one place- then using .withIndices("alias") -->
  this will cause me to lose all spring repository self-impl --> tons
  of boilerplate code.</li>
  </ol>
  
  <p>A similar problem is identified here - <a href="https://stackoverflow.com/questions/32015592/how-to-interact-with-elastic-search-alias-using-spring-data">How to interact with elastic search Alias using Spring data</a>
  but I am looking for a solution which is not overriding/making custom implementation as this would be too much for not using given repository methods.</p>
  
  <p>Looking for a better solution if possible or an insight to change my design / idea :)</p>