-
Notifications
You must be signed in to change notification settings - Fork 69
Switch from elasticsearch to PostgreSQL text search #465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from elasticsearch to PostgreSQL text search #465
Conversation
ea948e5
to
0ffd3ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was playing with it 😉 ❌ I noticed that you can't search part of a word. If I search "pequeña" I don't have Posts with "pequeñas" word inside, this a difference with the current usage with ES Worked fine:
Tested: Search logged out:Extra (the current behaviour with ES don't cover this)When user is logged out we want to filter by organization https://staging.timeoverflow.org/offers?org=2&q=prueba but don't apply org filter (only https://staging.timeoverflow.org/offers?org=2 https://staging.timeoverflow.org/offers?org=1 is filtering by organization). Analogously near search box you can filter by category ?cat=1 we want to accumulate the filters like https://staging.timeoverflow.org/offers?org=2&cat=1&q=pruebas search Posts with keyword 'pruebas' in organization 2 and category 1 Search logged in in org 1:Search logged in in org 2:Same URLs test, only to ensure that org filter is working, and it is ✔️ |
@enricostano I think we can solve that issue by using one of the following settings: https://github.com/Casecommons/pg_search#searching-using-different-search-features (some of them need extra PostgreSQL extensions). I'd try with |
@sseerrggii @enricostano Pushed #467 with partial word search working, via |
@sseerrggii @enricostano I think we can leave the "Extra" requirements proposed by Sergi for another branch, so we can move on this one (which simplifies our infra a lot 👌). What do you think? |
@enricostano @sseerrggii updated with develop and fixed conflicts! |
🍏 Tested 🍏 |
I would like to test the performance of this new approach using a production db dump, with hundreds of posts to search from. |
Speed Test (time to load page in chrome console) Logged in, search "angles" (search only in one organization's posts)
Logged in, search "las" (search only in one organization's posts)
Logged out, search "angles" (search in all posts)
Logged out, search "las" (search in all posts)
|
might be interesting to play with this https://www.postgresql.org/docs/9.5/textsearch-tables.html#TEXTSEARCH-TABLES-INDEX |
Yep, I just wanted to do some benchmark first. Even if "logged out search" (hitting the whole Post table) is not used by users (@sseerrggii 's says... I would like some numbers instead), I would look into indexes in any case. |
Relevant blog posts in order to tune our config: https://www.compose.com/articles/indexing-for-full-text-search-in-postgresql/ EDIT: for indexing look also at https://github.com/Casecommons/pg_search/wiki/Building-indexes (maybe a bit outdated) |
Basically in order to improve performance we need to:
|
Some more benchmarking: |
e4a4b54
to
aab779c
Compare
Post.active.of_active_members.search_by_query('angles').explain @sauloperez 👆 I'll try to add a couple of indexes on |
f6dcd78
to
5d0ec9e
Compare
I tried adding those indexes but since both columns are boolean PG never use them.... |
@sseerrggii says that's tested enough 😅 Let's merge it! |
Nice job @enricostano and @sseerrggii 👏 this is a very good infra and project change! |
…from-elastic-to-pg-search-la-buena"" This reverts commit 096fcce.
WAT
Elasticsearch is a dependency difficult to maintain and having to maintain a mirrored copy of the resources is also difficult, as you can see looking at the code deleted by this PR.
We already have PostgreSQL as a dependency and since our needs are quite simple we'll use the PostgreSQL built in Full Text Search.
The gem that I'm proposing is https://github.com/Casecommons/pg_search
Depends on
coopdevs/timeoverflow-provisioning#62
Extra
Closes #293