首页 > 解决方案 > 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. 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?

标签: elasticsearchindexing

解决方案


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).

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

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

The index option controls whether field values are indexed. 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 :)

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.


推荐阅读