Any reason not use PostgreSQL's built-in full text search on Heroku?

后端 未结 6 1206
死守一世寂寞
死守一世寂寞 2021-01-30 01:44

I\'m preparing to deploy a Rails app on Heroku that requires full text search. Up to now I\'ve been running it on a VPS using MySQL with Sphinx.

However, if I want to us

6条回答
  •  孤独总比滥情好
    2021-01-30 02:10

    Since I just went through the effort of comparing elastic search (1.9) against postgres FTS, I figured I should share my results since they're somewhat more current than the ones @gustavodiazjaimes cites.

    My main concern with postgres was that it did not have faceting built in, but that's trivial to build yourself, here's my example (in django):

    results = YourModel.objects.filter(vector_search=query)
    facets = (results
        .values('book')
        .annotate(total=Count('book'))
        .order_by('book'))
    

    I'm using postgres 9.6 and elastic-search 1.9 (through haystack on django). Here's a comparison between elasticsearch and postgres across 16 various types of queries.

        es_times  pg_times  es_times_faceted  pg_times_faceted
    0   0.065972  0.000543          0.015538          0.037876
    1   0.000292  0.000233          0.005865          0.007130
    2   0.000257  0.000229          0.005203          0.002168
    3   0.000247  0.000161          0.003052          0.001299
    4   0.000276  0.000150          0.002647          0.001167
    5   0.000245  0.000151          0.005098          0.001512
    6   0.000251  0.000155          0.005317          0.002550
    7   0.000331  0.000163          0.005635          0.002202
    8   0.000268  0.000168          0.006469          0.002408
    9   0.000290  0.000236          0.006167          0.002398
    10  0.000364  0.000224          0.005755          0.001846
    11  0.000264  0.000182          0.005153          0.001667
    12  0.000287  0.000153          0.010218          0.001769
    13  0.000264  0.000231          0.005309          0.001586
    14  0.000257  0.000195          0.004813          0.001562
    15  0.000248  0.000174          0.032146          0.002246
                      count      mean       std       min       25%       50%       75%       max
    es_times           16.0  0.004382  0.016424  0.000245  0.000255  0.000266  0.000291  0.065972
    pg_times           16.0  0.000209  0.000095  0.000150  0.000160  0.000178  0.000229  0.000543
    es_times_faceted   16.0  0.007774  0.007150  0.002647  0.005139  0.005476  0.006242  0.032146
    pg_times_faceted   16.0  0.004462  0.009015  0.001167  0.001580  0.002007  0.002400  0.037876
    

    In order to get postgres to these speeds for faceted searches I had to use an GIN index on the field with a SearchVectorField, which is django specific but I'm sure other frameworks have a similar vector type.

    One other consideration is that pg 9.6 now supports phrase matching, which is huge.

    My take away is that postgres is for most cases going to be preferrable as it offers:

    1. simpler stack
    2. no search backend api wrapper dependencies to contend with (thinking-sphinx, django-sphinx, haystack etc.). These can be a drag since they might not support the features your search back-end does (e.g. haystack faceting/aggregates).
    3. has similar performance and features (for my needs)

提交回复
热议问题