如何管理Elasticsearch索引数据

huangapple go评论53阅读模式
英文:

How to Management Elasticsearch Index data

问题

我正在使用Elasticsearch搜索产品。

每天对产品信息进行完整索引。

我正在删除并重新创建索引以进行清洗索引,但我不确定如何处理那个时候的产品搜索。

在进行完整清洗索引时,如何处理查询的标准方式如何?

在进行完整清洗索引时,我考虑在创建全新索引后通过状态检查来逻辑处理它,但我想知道是否有更好的方式。

英文:

I am using Elasticsearch to search for products.

Perform full indexing of product information on a daily basis.

I am deleting and recreating the index for clean indexing, but I am not sure how to handle product search at that time.

How about the standard way of handling queries at the time of clean full indexing?

During clean full indexing, I thought about processing it logically through a status check after creating a completely new index, but I wonder if there is a better way.

答案1

得分: 1

正确的做法是使用别名。您有当前的产品索引,让我们称之为 products-1,它与名称 products 别名关联。所有您的搜索查询都通过别名而不是索引名称进行。

当您需要重新索引您的产品时,您可以在一个名为 products-2 的新索引中执行此操作。当您完成索引并测试确保一切正常后,只需使用以下命令切换别名,您的搜索查询将不会中断:

POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "products-1",
        "alias": "products"
      }
    },
    {
      "add": {
        "index": "products-2",
        "alias": "products"
      }
    }
  ]
}

然后,您可以继续删除索引,或者如果您有信心,可以像这样一次性执行:

POST _aliases
{
  "actions": [
    {
      "remove_index": {
        "index": "products-1"
      }
    },
    {
      "add": {
        "index": "products-2",
        "alias": "products"
      }
    }
  ]
}
英文:

The correct way of doing it is by using an alias. You have the current product index, let's call it products-1 and it is aliased with the name products. All your search queries go through the alias name and not through the index name.

When you need to reindex your products, you do so but in a new index called products-2 and when you're done indexing and tested that everything went fine, you just switch the alias using the following command and your search queries will be carried out uninterrupted:

POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "products-1",
        "alias": "products"
      }
    },
    {
      "add": {
        "index": "products-2",
        "alias": "products"
      }
    }
  ]
}

You can then go ahead and delete the index or if you're confident you can do it in a single step like this:

POST _aliases
{
  "actions": [
    {
      "remove_index": {
        "index": "products-1"
      }
    },
    {
      "add": {
        "index": "products-2",
        "alias": "products"
      }
    }
  ]
}

huangapple
  • 本文由 发表于 2023年6月15日 11:06:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76478829.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定