什么是弹性搜索的索引 [英] What is an index in Elasticsearch

查看:145
本文介绍了什么是弹性搜索的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

弹性搜索中的索引是什么?一个应用程序有多个索引还是只有一个?
说说你为一些汽车制造商建立了一个系统。它涉及人,汽车,备件等。你有一个名为制造商的索引,还是有一个人的索引,一个是汽车索引,三分之一是备件?有人可以解释一下吗?

What is an index in Elasticsearch? Does one application have multiple indexes or just one? Let say you built a system for some car manufacturer. It deals with people, cars, spare parts etc. Do you have one index named manufacturer, or do you have one index for people, one for cars and a third for spare parts? Could someone explain?

推荐答案

好的问题,答案比预期的更细微。

Good question, and the answer is a lot more nuanced than one might expect. You can use indices for several different purposes.

最简单和最熟悉的布局克隆了什么你会期望从一个关系数据库。您可以(非常粗略地)想到一个数据库的索引。

The easiest and most familiar layout clones what you would expect from a relational database. You can (very roughly) think of an index like a database.


  • MySQL => Databases => Tables =>列/ li>
  • ElasticSearch => Indices => Types =>属性文档

ElasticSearch群集可以包含多个(数据库),它们又包含多个类型(表)。这些类型包含多个文档(行),每个文档都有属性(列)。

An ElasticSearch cluster can contain multiple Indices (databases), which in turn contain multiple Types (tables). These types hold multiple Documents (rows), and each document has Properties (columns).

所以在你的汽车制造场景中,你可能有一个 SubaruFactory 索引。在此索引中,您有三种不同的类型:

So in your car manufacturing scenario, you may have a SubaruFactory index. Within this index, you have three different types:


  • 人们

  • 汽车

  • Spare_Parts

  • People
  • Cars
  • Spare_Parts

每个类型都包含与该类型相对应的文档(例如,一个Subaru Imprezza文档住在 Cars type。此文档包含有关该特定车辆的所有详细信息。)

Each type then contains documents that correspond to that type (e.g. a Subaru Imprezza doc lives inside of the Cars type. This doc contains all the details about that particular car).

搜索和查询采用以下格式:http:// localhost:9200 / [index ] / [type] / [operation]

Searching and querying takes the format of: http://localhost:9200/[index]/[type]/[operation]

所以要检索Subaru文档,我可以这样做:

So to retrieve the Subaru document, I may do this:

  $ curl -XGET localhost:9200/SubaruFactory/Cars/SubaruImprezza

现在,现实是,指数/类型比我们在RDBM中使用的数据库/表抽象。它们可以被认为是方便的数据组织机制,具有增加的性能优势,具体取决于您设置数据的方式。

Now, the reality is that Indices/Types are much more flexible than the Database/Table abstractions we are used to in RDBMs. They can be considered convenient data organization mechanisms, with added performance benefits depending on how you set up your data.

为了演示一种截然不同的方法,很多人使用ElasticSearch用于记录。标准格式是为每一天分配一个新的索引。您的索引列表可能如下所示:

To demonstrate a radically different approach, a lot of people use ElasticSearch for logging. A standard format is to assign a new index for each day. Your list of indices may look like this:


  • logs-2013-02-22

  • logs -2013-02-21

  • logs-2013-02-20

ElasticSearch允许您要同时查询多个索引,所以这不是一个问题:

ElasticSearch allows you to query multiple indices at the same time, so it isn't a problem to do:

  $ curl -XGET localhost:9200/logs-2013-02-22,logs-2013-02-21/Errors/_search=q:"Error Message"

同时在最近两天内搜索日志。这种格式由于日志的性质而具有优势 - 大多数日志从来没有被看过,它们被组织在一个线性的时间流中。每个日志的索引更合乎逻辑,并提供更好的搜索性能。

Which searches the logs from the last two days at the same time. This format has advantages due to the nature of logs - most logs are never looked at and they are organized in a linear flow of time. Making an index per log is more logical and offers better performance for searching.

另一个完全不同的方法是为每个用户创建一个索引。想象一下,你有一些社交网站,每个用户都有大量的随机数据。您可以为每个用户创建一个索引。您的结构可能如下所示:

Another radically different approach is to create an index per user. Imagine you have some social networking site, and each users has a large amount of random data. You can create a single index for each user. Your structure may look like:


  • Zach的索引

    • 兴趣类型

    • 朋友类型

    • 图片类型


    • 兴趣类型

    • 朋友类型

    • 图片类型

    请注意,这种设置可以以传统的RDBM方式轻松完成(例如用户索引,与爱好/朋友/图片作为类型)。所有用户都将被投入到一个巨大的索引中。

    Notice how this setup could easily be done in a traditional RDBM fashion (e.g. "Users" Index, with hobbies/friends/pictures as types). All users would then be thrown into a single, giant index.

    相反,由于数据组织和性能原因,有时将数据分开。在这种情况下,我们假设每个用户都有很多数据,我们希望它们分开。 ElasticSearch没有问题让我们为每个用户创建一个索引。

    Instead, it sometimes makes sense to split data apart for data organization and performance reasons. In this scenario, we are assuming each user has a lot of data, and we want them separate. ElasticSearch has no problem letting us create an index per user.

    这篇关于什么是弹性搜索的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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