【问题标题】:How to use ingest pipelines on already indexed documents?如何在已编入索引的文档上使用摄取管道?
【发布时间】:2019-07-01 16:00:14
【问题描述】:

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

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

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

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

【问题讨论】:

标签: php elasticsearch kibana foselasticabundle


【解决方案1】:

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

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

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

以下是步骤摘要:

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

以下是您如何通过管道使用 Reindex API

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

如果这有帮助,请告诉我!

【讨论】:

  • 补充说明,如果您的索引太大并且想查看重新索引操作的状态,而它仍在后台处理,请参阅Task API,这将帮助您信息,例如处理了多少文档以及在重新索引操作期间还剩下多少。 elastic.co/guide/en/elasticsearch/reference/current/…
【解决方案2】:

所以,经过一段时间后,我找到了一种更有效的方法来解决我的问题:Dynamic templatesIndex 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 2013-08-06
    • 1970-01-01
    • 2021-11-08
    相关资源
    最近更新 更多