首页 > 解决方案 > 如何将(文本)字段添加到 pgsync / elasticsearch 中的所有字段?

问题描述

我正在探索pgsync为某些表添加弹性搜索支持,但是,我希望能够将所有文本字段复制到一个“全部”字段。Elastic 以映射到组字段的形式对此提供支持copy-to,请参见此处

像这样:

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "first_name": {
        "type": "text",
        "copy_to": "full_name" 
      },
      "last_name": {
        "type": "text",
        "copy_to": "full_name" 
      },
      "full_name": {
        "type": "text"
      }
    }
  }
}

如何在 PGSync schema.json 中实现这个组字段?

标签: elasticsearchmappingschemapgsync

解决方案


您可以通过创建transform具有类型的节点在 pgsync 中执行此操作mapping这是此处定义的书籍示例如何实现此目的的示例

[
    {
        "database": "book",
        "index": "book",
        "nodes": {
            "table": "book",
            "columns": [
                "id",
                "isbn",
                "title",
                "description"
            ],
            "transform": {
                "mapping": {
                    "title": {
                        "type": "text",
                        "copy_to": "full_name" 
                    },
                    "description": {
                        "type": "text",
                        "copy_to": "full_name" 
                    },
                    "full_name": {
                        "type": "text"
                    }
                }
            }
        }
    }
]

推荐阅读