ElasticSearch vs MongoDB for exact text search

38 Views Asked by At

Hi I have a collection of documents with multiple fields in them. One of the fields is called "address". And I simply need to find the value of this address.

I have a Mongo instance and been testing querying it. I get about 15ms on single queries from local machine to hosted instance of Mongo. However, on concurrent requests to it (100 requests), the avg latency of each request became 425ms! (I have put an index on the "address" field).

I'd like to ask if ElasticSearch would essentially be similar, I know it's more used for search engine, but in my case the search is so simple, I simply have an index on the "address" field. In such cases is ElasticSearch still much more optimized that it still would be much faster than Mongo?

Thanks.

I have tried hosting my mongo instance and wrote golang code to test the endpoint and time the latency.

E.g.:

func (s *store) TestMongoQuery(ctx context.Context, address string, curTime time.Time) (string, error) {
    // Perform Query
    watchlistCollection := s.dbManager.Collection(WatchlistConnection, WatchlistCollection, cbmongo.ReadTypePrimary)
    filter := bson.M{"address": address}
    options := options.FindOne().SetHint(bson.M{"address": 1})

    var result Entity
    err := watchlistCollection.FindOne(ctx, filter, options).Decode(&result)
    if err != nil {
        if err == mongo.ErrNoDocuments {
            return "", nil
        }
        return "", err
    }
    return result.Address, nil
}
0

There are 0 best solutions below