I am looking for some high level advice on how to get started with the following requirements:
We have a ruby sinatra API service that is running on heroku that syncs users email with our system.
We store the users emails in a postgres database that is broken into subject and text and html fields.
I want to use elasticsearch to search these emails but the search must only search for emails that are in the users inbox.
Can anyone give me my first steps in how to index the postgres emails table and also how to filter the search so that it is confined to only the users emails?
The schema for the emails table is:
CREATE TABLE emails
(
id serial NOT NULL,
subject text,
body text,
personal boolean,
sent_at timestamp without time zone,
created_at timestamp without time zone,
updated_at timestamp without time zone,
addresses text,
account_id integer NOT NULL,
sender_user_id integer,
sender_contact_id integer,
html text,
folder text,
draft boolean DEFAULT false,
check_for_response timestamp without time zone,
send_time timestamp without time zone,
send_time_jid text,
check_for_response_jid text,
message_id text,
in_reply_to text,
CONSTRAINT emails_pkey PRIMARY KEY (id),
CONSTRAINT emails_account_id_fkey FOREIGN KEY (account_id)
REFERENCES accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT emails_sender_contact_id_fkey FOREIGN KEY (sender_contact_id)
REFERENCES contacts (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT emails_sender_user_id_fkey FOREIGN KEY (sender_user_id)
REFERENCES users (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE
)