如何在已经索引的文档上使用摄取管道?

How to use ingest pipelines on already indexed documents?

我一直在使用 FOSElasticaBundle 将我的文档(它们是通过 Doctrine 保存在数据库中的 Symfony 项目中的实体)索引到 Elastic Search 中。 FOSElastica 在所有文档之后进行自动映射和索引。

问题是我想对每个文档应用一些操作(在已经索引的文档和之后的文档上),所以管道和无痛似乎是一个很好的解决方案。

但是,我无法理解如何将管道应用到已编入索引的文档,您知道怎么做吗?

我看到您可以在 ES 请求后添加 "pipeline=my_pipeline_name",但您可以对单个文档执行此操作,而我希望它影响所有文档。

您可以在将数据从 一个索引 移动到 另一个索引 时使用 Pipeline

您需要使用 Reindex API 才能在 movement/ingestion_process 从一个索引到另一个索引期间对数据执行。

注意:这是索引级操作意味着它会影响所有文件。

步骤总结如下:

  • 创建 temporary_index
  • source_index 重新索引到 temporary_index 使用 Reindex API。还包括管道(下面提供了示例查询)
  • 删除 re-create source_index。确保在创建索引时也包含映射。
  • 使用 source_index 作为目标名称和 temporary_index 作为源名称执行相同的查询 没有管道

下面是如何使用 Reindex API 和管道

POST _reindex
{
  "source": {
    "index": "source_index_name"
  },
  "dest": {
    "index": "temporary_index",
    "pipeline": "some_ingest_pipeline"
  }
}

如果有帮助请告诉我!

所以,一段时间后,我找到了一种更有效的方法来解决我的问题:Dynamic templates and Index templates

实际上,我在 ElasticSearch 无法识别某些类型的字段(如日期或 geo_point)时遇到了麻烦,因此我在模板的帮助下将它们强制用于特定命名的字段。

如果您想要我在 FOSElastica 中的配置示例 (doc is here):

fos_elastica:
    serializer: 
        serializer: jms_serializer
    clients:
        default: 
            host: localhost 
            port: 9200
    index_templates: # https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-templates.html
        base_template: # this is a custom name for the index template
            client: default
            template: "*" # this is where you define which indices will use this template
            types:
                _doc: # this is where you define which types will use this (_doc stands for every type/documents)
                    dynamic_templates: # https://www.elastic.co/guide/en/elasticsearch/reference/6.8/dynamic-templates.html
                        dynamic_date_template: # this is a custom name for the dynamic field template
                            match_pattern: regex
                            match: created|updated|tpq_date|taq_date
                            mapping:
                                type: date
                        dynamic_location_template:
                            match: location
                            mapping:
                                type: geo_point