027 ElasticSearch ---- Text Technology 02 --- Getting Started

1. Basic Concepts

Elasticsearch also a full-text search based on Lucene library, but also the nature of the stored data, many of the concepts and MySQL similar.

 

Note: Before version 6.0 has type (type) concept, type the equivalent relational database tables, ES will completely delete type in the official version ES9.0 .
Create a database index is equivalent to a relational database or database table top talking about?
1, if it means the equivalent of a database index database can create many different types of documents, which in the ES is allowed.
2. If the equivalent of the table , says an index library can store the same type of document , ES official suggested in an index database to store only the same type of document.

2. Create an index Library

 

ES index library is a logical concept, which includes a word list and a list of documents , stored in the same type of document library in the same index. It is equivalent to MySQL tables, or the equivalent of a collection Mongodb.
The language on the index:
the index (noun): ES is based on a built Lucene search service, which qualified from the index database search index data.
Index (verb): index database just created it is empty, the process of adding data to the library index is called index.

 

Index below describes how to create two libraries, their working principle is the same, are the client sends commands to the ES services.

1) Use postman this tool to create:
PUT HTTP: // localhost: 9200 / index database name

The request to create an index format:

  • Request mode: PUT

  • Request path: / index library name

  • Request parameters: json Format

{
    "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0
      }
}

settings: Set the index repository
number_of_shards: setting the number of fragments, fragments generally provided in a plurality of clusters, a represents the index database is split into multiple pieces each different storage nodes, ES improved processing power and high availability , entry procedures use a stand-alone environment, is set to 1 here.
number_of_replicas: set the number of copies, setting a copy is to improve reliability, stand-alone environment setup ES is zero.

Another visit http: // localhost: 9100 /, the use of plug-in head

You can see the index creation succeeded.

 

2) the use of plug-in creates head

 

Box pops up as follows:

After clicking ok, visible

3. Create a map

(1) concept note

Index (the index can be understood as Mysql database tables) has been, is sure to add data. However, it must be defined before adding the mapping data.

Mapping is the process definition document, which document contains fields that whether to save, whether the index, such as whether the word

 

In the index each document contains one or more field, create a mapping process is to create an index field to the library, below is a document and field
analogy with the concept of relational databases:
Document (Document) ------ ---------- row recording
field (field) ------------------- columns column

(2) create a map

We need to program information is stored into the ES, where we create a mapping program information, first to a simple mapping, as follows:
Postman tool send: post http: // localhost: 9200 / index database name / type name / _mapping
create leyou type of map, including a total of three fields: name, description, studymondel
due ES6.0 version of the type not completely removed, we do not have to type a name a special meaning.
post request: http: // localhost: 9200 / leyou / doc / _mapping
said: create a map in the doc type in leyou index database . doc is the type of name, you can customize in ES6.0 want to weaken the concept of type, give it a name no specific business sense.

Map created successfully, view the head interface:

(3) create a document

ES in the document (document) is equivalent to MySQL database table a record (Row) .
Send: put or Post http: // localhost: 9200 / leyou / doc / id value
(id value if not specified ES automatically generated ID)
HTTP: // localhost: 9200 / xc_course / DOC / 4028e58161bcf7f40161bcf8b77c0000

{ 
  "Name": "Bootstrap Development Framework", 
  "the Description": "Bootstrap by Twitter launched a front page development framework, to use more widely in the industry this development framework contains a lot of CSS, JS code, you can. help developers (especially not good programmers to develop the page) to easily achieve a beautiful interface effects without browser limitations ",. 
  " studymodel ":" 201001 " 
}

Use postman test:

By head query data:

(4) search for documents

<1> according to the course id query document
sent: get http: // localhost: 9200 / xc_course / doc / 4028e58161bcf7f40161bcf8b77c0000
use postman test:

<2> Query all records

http://localhost:9200/leyou/doc/_search

 

<3> query name includes a record spring keyword

http://localhost:9200/leyou/doc/_search?q=name:bootstrap

 

Guess you like

Origin www.cnblogs.com/luckyplj/p/11592625.html