简体   繁体   English

我们是否需要专门在 elasticsearch 中创建索引?

[英]do we need to create index specifically in elasticsearch?

I'm quite new to elasticsearch and I know index in elasticsearch has 2 meanings, it either means the logical namespace that maps to shards in a node or index some data as that we do in relational database management systems.我对 elasticsearch 很陌生,我知道 elasticsearch 中的 index 有两个含义,它要么意味着映射到节点中分片的逻辑命名空间,要么像我们在关系数据库管理系统中所做的那样索引一些数据。 So normally in SQL I would use 'Create index' to create a single or composite index on a field or multiple fields, how do I do that in elasticsearch or does elasticsearch do the index (verb) automatically that can improve search efficiency?所以通常在 SQL 中,我会使用“创建索引”在一个或多个字段上创建单个或复合索引,我如何在 elasticsearch 中执行此操作,或者 elasticsearch 自动执行索引(动词)以提高搜索效率?

You were right that the index in elasticsearch internally mapped to shards and replicas but you are getting confused with the naming/meaning of an index wrt to RDBMS(in RDBMS its created to increase the search efficiency).您说对了,elasticsearch 中的索引在内部映射到分片和副本,但是您对 RDBMS 索引的命名/含义感到困惑(在 RDBMS 中创建它是为了提高搜索效率)。

While in Elatsicsearch, an index contains a mapping(where you define various fields, their data-type, and analyzer), for more info refer to Mapping in elasticsearch在 Elatsicsearch 中,索引包含一个映射(您可以在其中定义各种字段、它们的数据类型和分析器),有关更多信息,请参阅弹性搜索中的映射

Now, when you define a field in elasticsearch it accepts a few parameters and one of which param is also called index , which according to the same official doc is现在,当您在 elasticsearch 中定义一个字段时,它接受一些参数,其中一个参数也称为index ,根据同一个官方文档是

The index option controls whether field values are indexed. index 选项控制是否对字段值进行索引。 It accepts true or false and defaults to true.它接受真或假并默认为真。 Fields that are not indexed are not queryable.未编入索引的字段不可查询。

This means, the field will be part of Elasticsearch inverted index, which is used to query/search the data, and obviously without this option you will not be able to search this particular field and as this is part of the inverted index(faster data structure to increase search performance), you will implicitly get the better search performance :)这意味着,该字段将成为 Elasticsearch 倒排索引的一部分,用于查询/搜索数据,显然如果没有此选项,您将无法搜索该特定字段,因为这是倒排索引的一部分(更快的数据结构以提高搜索性能),您将隐式获得更好的搜索性能:)

As mentioned in the official doc default value of index param is true, so to answer your question, you don't need to define the index specifically in Elasticsearch.正如官方文档中提到的 index param 的默认值是 true,所以要回答您的问题,您不需要在 Elasticsearch 中专门定义索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM