In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Start the first step.
Let's start with a simple tutorial that covers basic concepts such as indexing, search, and aggregations. Through this tutorial, we can give you a general idea of what Elasticsearch can do and how easy it is to use.
We will introduce some terminology and basic concepts one after another, but it doesn't matter if you don't fully understand it right away. We will discuss these contents in more depth in the various chapters of this book.
So sit down and start feeling the power of Elasticsearch at a whirlwind speed.
Let's set up an employee directory
Suppose we happen to be working at Megacorp, and the human resources department needs us for some purpose to create an employee directory that promotes human care and real-time collaborative work, so it has the following different needs:
Data can contain labels, numbers, and plain text for multiple values.
Retrieve all information about any employee.
Support structured search, such as finding employees over the age of 30.
Supports simple full-text search and more complex phrase (phrase) search
Highlight keywords in search results
Be able to use chart management to analyze these data
Index employee documents
The first thing we need to do is to store employee data, and each document represents an employee. The act of storing data in Elasticsearch is called indexing, but before indexing, we need to know where the data should be stored.
In Elasticsearch, documents belong to a type (type), and these types exist in the index (index), so we can draw some simple comparison diagrams to compare traditional relational databases:
Relational DB-> Databases-> Tables-> Rows-> Columns
Elasticsearch-> Indices-> Types-> Documents-> Fields
An Elasticsearch cluster can contain multiple indexes (indices) (databases), each index can contain multiple types (types) (tables), each type contains multiple documents (documents) (rows), and then each document contains multiple fields (Fields) (columns).
The distinction between the meaning of "index"
You may have noticed that the word index has different meanings in Elasticsearch, so it is necessary to make a distinction here:
Index (noun) as mentioned above, an index (index) is like a database in a traditional relational database, it is where related documents are stored, and the plural of index is indices or indexes.
Index (verb) "index a document" means to store a document in an index (noun) so that it can be retrieved or queried. This is much like the INSERT keyword in SQL, except that if the document already exists, the new document will overwrite the old one.
Inverted index traditional databases add an index to a specific column, such as an B-Tree index, to speed up retrieval. Elasticsearch and Lucene use a data structure called inverted index (inverted index) to achieve the same goal.
By default, all fields in the document are indexed (with an inverted index) so that they are searchable.
We will discuss it in more detail in the inverted indexing section.
So to create an employee directory, we will do the following:
Index each employee's document (document), and each document contains all the information about the corresponding employee.
The type of each document is employee.
The employee type belongs to index megacorp.
The megacorp index is stored in the Elasticsearch cluster.
In fact, these are very easy (although there seem to be many steps). We can perform the completed operation with a single command:
PUT / megacorp/employee/1
{
"first_name": "John"
"last_name": "Smith"
"age": 25
"about": "I love to go rock climbing"
"interests": ["sports", "music"]
}
We see that path:/megacorp/employee/1 contains three pieces of information:
Name description
Megacorp index name
Employee type name
1 the ID of this employee
The request entity (JSON document) contains all the information about the employee. His name is "John Smith". He is 25 years old and likes rock climbing.
It's easy! It does not require you to do additional administrative operations, such as creating an index or defining the data type of each field. We can index documents directly, Elasticsearch has built-in all the default settings, and all administrative operations are transparent.
Next, let's add more employee information to the directory:
PUT / megacorp/employee/2
{
"first_name": "Jane"
"last_name": "Smith"
"age": 32
"about": "I like to collect rock albums"
"interests": ["music"]
}
PUT / megacorp/employee/3
{
"first_name": "Douglas"
"last_name": "Fir"
"age": 35
"about": "I like to build cabinets"
"interests": ["forestry"]
}
Results:
[root@master elasticsearch] #
Curl-I-XPUT 127.0.0.1:9200/megacorp/employee/1-d'{"first_name": "John", "last_name": "Smith", "age": 25, "about": "I love to go rock climbing", "interests": ["sports", "music"]}'
Result: the cluster data directory has an extra index megacorp name (the indices directory is the plural of the index name)
[root@master elasticsearch] #
Ls-l / tmp/elasticsearch/data/elasticsearch-cluster/nodes/0/indices/megacorp/total 24drwxr-xr-x 5 elasticsearch elasticsearch 4096 May 15 19:32 0drwxr-xr-x 5 elasticsearch elasticsearch 4096 May 15 19:31 1drwxr-xr-x 5 elasticsearch elasticsearch 4096 May 15 19:32 2drwxr-xr-x 5 elasticsearch elasticsearch 4096 May 15 19:31 3drwxr-xr-x 5 elasticsearch elasticsearch 4096 May 15 19:33 4drwxr-xr-x 2 elasticsearch elasticsearch 4096 May 15 19:33 _ state
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.