pgsync icon indicating copy to clipboard operation
pgsync copied to clipboard

How to add WHERE clause to schema?

Open gunererd opened this issue 3 years ago • 3 comments

Sorry if asked before but I couldn't find in examples, documentation or closed issues but how we can add where clause to schema? Say that I'd like to sync only the rows with column status is equal to 100.

gunererd avatar Feb 16 '22 11:02 gunererd

This has come up before. Its not easy to come up with a generic user friendly configuration based query language to support this functionality.

Your use case is probably straightforward but to completely support the WHERE clause is not.

The easiest way is to leverage the plugin functionality. Here is an example and documentation

toluaina avatar Feb 16 '22 12:02 toluaina

Thanks for your attention. As far as I understand plugins still fetches the data from postgresql and filter out just before indexing into elasticsearch right? @toluaina

gunererd avatar Feb 16 '22 14:02 gunererd

You are right this wasn't so easy. I have made a change to how the plugin works in the master branch. So you can do this now. Here is an example

class MyFilterPlugin(plugin.Plugin):
    """Example Filter plugin."""

    name: str = "Filter"

    def transform(self, doc: dict, **kwargs) -> dict:
        """Demonstrates how to perform a filter."""
        doc_id = kwargs["_id"]
        doc_index = kwargs["_index"]
        if doc["id"] == 1:
            return None

        return doc

toluaina avatar Feb 18 '22 13:02 toluaina