你可以使用Elasticsearch来查询数据库,而不是使用标准数据库吗?

huangapple go评论63阅读模式
英文:

Can I use Elasticsearch for query DB in replace of standard DB?

问题

MongoDB,例如,很不错,但它没有全文搜索(Atlas Search 有,但它是不同的东西)。此外,您需要显式地对字段进行索引。

Elastic 允许对文档中的每个字段进行动态索引。所以基本上每个字段都被索引了,您可以非常快速地查询所有的数据(顺便问一下,这样做好吗?只需添加大量文档并让它们都被索引?)

所以我想当我只需要查询数据,没有任何变更或 ACID 事务时 - 例如 - 给我列出在 StackOverflow 公司工作的员工名单,然后添加一个筛选条件,筛选出在开发者角色中工作超过 5 年的人,然后添加一个名字以 "Dan" 开头的全文搜索。所有这些都可以通过 Elastic 实现。

所以它可能是 MongoDB/MySQL/Postgres 等的完全替代品 - 仅用于查询。不是吗?

英文:

MongoDB, for example, is great but it has no full-text search (Atlas Search does, but its a different thing). Also you need to explicitly index fields.

Elastic allows dynamic indexing per every field in the document. So basically every field is indexed and you can query against all of your data very fast (btw is it good to do so? just drop tons of documents and let them all be indexed?)

So I guess that when I need just to query data, without any mutations or ACID transactions - for example - give me the list of employees who work for a company StackOverflow, then add filter of who works for more than 5 years in role of developer, then add full-text search for name starts with "Dan". All of these can be achieved by Elastic.

So probably it can be a full replacer for MongoDB/MySQL/Postgres/etc - for query only. Isn't it?

答案1

得分: 2

Certainly, here is the translation:

  1. Elasticsearch支持连接,父子查询,但与MySQL相比性能较差。
  2. Elasticsearch查询数据速度较慢,因为有提升查询(boost query)。
  3. 注意聚合查询(aggr),如计数和去重,存在精度问题。因为Elasticsearch是基于分片设计的,来自多个分片的聚合会较慢且不够准确。
  4. 精通Elasticsearch查询计数,因为Elasticsearch DSL比传统SQL更复杂。
  5. Elasticsearch使用比其他数据库更多的磁盘空间,因为需要对文本字段进行分析。

查询性能对于各种类型的数据库都很重要。

英文:

Yes, but still there are something you need take into consideration.

  1. elasticsearch supports join , parent-child query with very poor performance comparing to mysql.
  2. elasticsearch query data slower than other db, cause of boost query.
  3. Pay attention to aggr, such as count, distinct, there is a precision problem. As elasticsearch is designed with shards, aggregation from mutilple shards will be slow and inaccuracy.
  4. Proficiency of elasticsearch query counts, as elasticsearch DSL is more complex than traditional SQL.
  5. elasticsearch use more disk than other db, cause of analyzation of text field.

Query performance counts for every kinds of db.

huangapple
  • 本文由 发表于 2023年4月11日 05:27:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980878.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定