mnaa
mnaa

Reputation: 424

Reindex and alias - avoid duplicate search results

I am using one alias for search with one index index_1 with is_write_index set to true. Due to mapping changes I need to reindex and this is my indexing process.

  1. Create a new index index_2 with the new mapping
  2. Reindex index_1 to index_2
  3. Add the alias used in index_1 to index_2 with is_write_index set to true for index_2
  4. Reindex index_1 to index_2 to sync the latest changes
  5. Delete index_1

The issue I am having is that from step 3, queries to the alias is returning duplicate results. How to avoid this issue ?

Upvotes: 3

Views: 1986

Answers (1)

mnaa
mnaa

Reputation: 424

Found the answer, the short term solution I found is to use filters when setting aliases to filter out duplicate results from index_2. So for example.

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "index_1",
        "alias": "aliasName",
        "is_write_index": true
      }
    },
    {
      "add": {
        "index": "index_2",
        "alias": "aliasName",
        "filter": {
          "term": {
            "myGuaranteedToExistField": "impossibleToFindValue"
          }
        }
      }
    }
  ]
}

When indexing is done and things are verified I can flip the indices. Not sure if this is the best solution though but it works.

Upvotes: 1

Related Questions