Basic Setup
We’ll start simple, with one table about blog posts that we need to be indexed as is.
-
(optional) for sandbox, do cleanup:
DROP PUBLICATION IF EXISTS "search";
curl -XDELETE 'http://127.0.0.1:9200/postgres'
-
create table(s):
CREATE TABLE public.posts ( id bigserial NOT NULL, title text NOT NULL DEFAULT '', content text NOT NULL DEFAULT '', PRIMARY KEY (id) );
-
configure table: (wouldn’t be required in future)
COMMENT ON TABLE public.posts IS 'index:",all"'; -- index all fields by default
-
expose the table in a publication
CREATE PUBLICATION "search" FOR TABLE public.posts;
-
add some data
INSERT INTO public.posts( title, content) VALUES ( 'Post 1', 'Super content here'); INSERT INTO public.posts( title, content) VALUES ( 'Post 2', 'Boring news article');
-
restart search-replica
-
add more content
INSERT INTO public.posts( title, content) VALUES ( 'This is streaming replication', 'how long did it take to arrive in Elastic'); INSERT INTO public.posts( title, content) VALUES ( 'Im volcano', 'My name is Eyjafjallajökull'); UPDATE public.posts SET content='Updated interesting article' WHERE title='Post 2';