How to add (text)fields to all field in pgsync / elasticsearch?

292 views Asked by At

I am exploring pgsync to add elasticsearch support for some tables, however, I would like to be able to copy all the textfields to one "all" field. Elastic has support for this in the form of a mapping to a group field, with copy-to, see here

Like this:

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"
      }
    }
  }
}

How can I achieve this group field in PGSync schema.json?

1

There are 1 answers

0
taina On BEST ANSWER

You can do this in pgsync by creating a transform node with a mapping type. Here is an example of how to achieve this for the book example defined here

[
    {
        "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"
                    }
                }
            }
        }
    }
]