弹性搜索:一个具有自定义类型的索引来区分文档模式 VS 多个索引,每个文档类型一个? [英] Elastic Search: One index with custom type to differentiate document schemas VS multiple index, one per document type?

查看:42
本文介绍了弹性搜索:一个具有自定义类型的索引来区分文档模式 VS 多个索引,每个文档类型一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ES 方面没有经验(我的背景更多是关系数据库),我正在努力实现在我的 Web 应用程序中有一个搜索栏来搜索它的全部内容(或我愿意的内容)的目标在 ES 中索引).

I am not experienced in ES (my background is more of relational databases) and I am trying to achieve the goal of having a search bar in my web application to search the entire content of it (or the content I will be willing to index in ES).

实现的架构是 Jamstack 和 gatsby 应用程序,从一个 Strapi 应用程序(无头 cms)获取内容(有时在构建时,有时在运行时).中间自己开发了一个微服务,将trapi应用中创建的文档写入到ES数据库中.此时,所有文档都只有一个索引,不分类型.

The architecture implemented is Jamstack with a gatsby application fetching content (sometimes at build time, sometimes at runtime) from a strapi application (headless cms). In the middle, I developed a microservice to write the documents created in the strapi application to the ES database. At this moment, there is only one index for all the documents, regardless the type.

我的问题是,随着应用程序的增长和创建不同类型的文档(有时彼此之间非常不同,例如我可以拥有一篇文章(新闻)和一家医院)我很难正确查询数据库因为我在进行查询时必须定义很多特定条件(以涵盖所有类型的文档).

My problem is, as the application grows and different types of documents are created (sometimes very different from one another, as example I can have an article (news) and a hospital) I am having hard time to correctly query the database as I have to define a lot of specific conditions when making the query (to cover all types of documents).

我对此的解决方案是只保留一个索引并将查询分解为多个索引,当用户点击搜索按钮时,这些查询将运行,结果将在呈现之前合并在一起,或者将唯一的索引分解为几个,每个文档一个,这让我产生了另一个疑问,是否可以一次查询多个索引并在查询中定义特定的索引字段?

My solution to this is to keep only one index and break down the query in several ones and when the user hits the search button those queries are run and the results will be joined together before being presented OR break down the only index into several ones, one per document which leads me to another doubt, is it possible to query multiple indexes at once and define specific index fields in the query?

哪种方法最好?我希望我能在这方面明确自己.

Which is the best approach? I hope I could make my self clear in this.

提前致谢.

推荐答案

根据您提供的示例,其中一种类型的文档可以是 news 类型,另一种类型是 hospital,创建多个索引是有意义的(但你还需要告诉你有多少这样的不同类型).这两种方法各有利弊,一旦您了解了它们,您就可以根据自己的用例选择一种.

According to the example you provided, where one type of document can be of type news and another type is hospital, it makes sense to create multiple indices(but you also need to tell, how many such different types you have). there are pros and cons with both the approach and once you know them, you can choose one based on your use-case.

在我开始列出优点/缺点之前,您的另一个问题的答案是您可以使用 多搜索 API.

Before I start listing out the pros/cons, the answer to your other question is that you can query multiple indices in a single search query using multi-search API.

单一索引的优点

  1. 减少多个索引的管理开销(这就是为什么我问您的应用程序中可能有多少这样的索引).
  2. 因为数据集中在一个地方,所以搜索查询的性能更高.

缺点

  1. 您正在为不同类型的文档编制索引,因此您必须包含一个复杂的过滤器来获取您需要的数据.
  2. 相关性不会很好,因为您有多种文档会影响相似性算法 (BM25) 的 IDF,并影响相关性.

拥有不同索引的优点

  1. 最好根据数据的属性分离数据,以获得更好的相关结果.
  2. 您的搜索查询不会很复杂.
  3. 如果您拥有非常庞大的数据,那么分解数据、获得最佳分片大小和更好的性能是有意义的.

缺点

  1. 更多的管理开销.
  2. 如果您需要在所有索引中搜索,则必须实现多重搜索并等待所有索引搜索结果,这可能代价高昂.

这篇关于弹性搜索:一个具有自定义类型的索引来区分文档模式 VS 多个索引,每个文档类型一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆