Learn about ElasticSearch in this article

The Document (the Document)

  1. ElasticSearch is document-oriented, and a document is the smallest unit of all searchable data

    Such as:

    • Log entries in log files
    • Specific information about a song
    • A word specific content
  2. The document is serialized to JSON format and saved in ElasticSearch

    • A JSON object consists of fields
    • Each field has a corresponding field type (string/numeric/Boolean/date/binary/range)
  3. Each document has a Unique ID

    • You can specify your own ID
    • Generated automatically by ElasticSearch

JSON document

In ElasticSearch, a document contains a series of fields. Equivalent to a record in our relational database

Why is ElasticSearch using JSON files? JSON documents are relatively flexible and do not require predefined formats.

Fields can be specified themselves or automatically calculated by ElasticSearch. JSON supports a variety of data types. In addition to regular types, it also supports arrays and nesting of types.

Metadata for the document

What is metadata? Metadata is the relevant information used to annotate documents. Each document in ElasticSearch is annotated with a set of metadata.

  • _id Indicates the unique ID of a document
  • _index Indicates the index name of the document
  • _type Specifies the type to which the document belongs
  • _source The original Json data of the document
  • _all 7.0 was abolished at the beginning, which integrates all fields of the content field
  • _version Version of a document, which can solve the problem of document conflict in a large number of concurrent requests
  • _score Scores documents for relevance to search

The index

An index can be thought of as a container of documents, an aggregated representation of a class of documents.

  • IndexEmbodies the concept of logical space, each index has its ownMappingDefines the field names and field types used to describe the document
  • ShardThe concept of physical space is reflected in the index data are scattered inshardOn the.

Setting and mapping can be set on an index

  • settingUsed to define how the index is distributed on the shard, how many shards are required, and how the data is distributed
  • mappingThe field type and description used to describe the index

Different semantics of indexes

Indexes mean different things in different contexts. ES refers to a collection of documents, and is a noun attribute. When writing a document to ES, it is also called an index, which refers to the process of creating an inverted index of the document to ES. Inverted indexing is an important concept in search engines. We also come across indexes in everyday life, like dictionary catalog lookups.

TYPE

Type has been Deprecated since ElasticSearch 6.0. As of ElasticSearch 7.0, only one Type _doc can be created per index.

ElasticSearch vs. relational databases

RDBMS Elastic Search
Table Index(Type)
Row Document
Column Field
Schema Mapping
SQL DSL

As can be seen from the table above

  1. ESIn theIndexEquivalent to a relational databasetable
  2. ESIn theDucumentYou can view it as a relational databaserecord
  3. ESIn theColumnYou can view it as a relational databasefield
  4. ESIn theMappingThink of it as a relational databaseThe table definition
  5. For relational databases we useSQLQuery, used in ESDSLTo query

There are more important differences besides the above analogy

  1. In need of dataThe full text retrieval, to the resultsCorrelation scoreWhen, ES is relatively more advantageous
  2. When the data is neededTransaction managementWhen it’s more demanding, it’s obviously traditionalRDBMSMore suitable for

REST API

To facilitate integration with systems in other languages, ES provides REST apis to obtain ES data results.

In Kibana, there is an index management tool. You can see a detailed index description.

Common REST API

  1. View index information

    GET {index_name}
  2. View index document totals

    GET {index_name}/_count
  3. Wildcard query index

    GET _cat/indices/kibana*
  4. Query the index whose status is green

    GET _cat/indices? v&health=green