Description: elasticsearch is currently the most popular search engine, powerful and very popular. The feature is the inverted index, which is very efficient in the field of fuzzy search for massive data. Elasticsearch installation and usage reference: http://t.csdn.cn/yJdZb.
This article introduces the index library (index) operation and document (document) operation in es, which is equivalent to the table operation and data operation of the database.
Index library (index) operations
Create an index library
Format: PUT /index library name
PUT /student
{
# 映射,索引中文档的约束
"mappings": {
# 字段
"properties": {
# 姓名
"name":{
# 类型为text,表示此字段参与分词
"type":"text",
# 分词器为ik_smart
"analyzer": "ik_smart"
},
# 年龄
"age":{
"type": "integer"
},
# 个人信息
"info":{
"type":"keyword"
}
}
}
}
created successfully
find index library
Format: GET /index library name
GET /student
delete index library
Format: DELETE /index library name
DELETE /student
modify index library
Format: PUT /index library name/_mapping
Modifying the index library can only add fields, and cannot modify the original index library structure, such as adding a hobby field, the type is keyword, and does not participate in word segmentation;
PUT /student/_mapping
{
"properties":{
"hobby":{
"type":"keyword"
}
}
}
Document Operations
add document
Format: POST /index library name/_doc/ID
Adding a document is equivalent to adding a piece of data, such as adding a document in the student index library;
POST /student/_doc/1
{
"name":"zhangsan",
"age":"35",
"info":"中国人",
"hobby":"reading"
}
find documentation
Format: GET /index library name/_doc/ID
GET /student/_doc/1
delete document
Format: DELETE /index library name/_doc/ID
DELETE /student/_doc/1
modify document
Format: PUT /index library name/_doc/ID or POST /index library name/_update/ID
# 方式一:全量修改,会删除旧文档,添加新文档
PUT /student/_doc/1
{
"name":"lisi",
"age":"60",
"info":"中国人",
"hobby":"walk"
}
# 方式二:增量修改,修改指定字段
POST /student/_update/1
{
"doc":{
"name":"wangwu"
}
}
Summarize
Add, create, modify using POST, PUT, search using GET, delete using DELETE