elasticsearch官方文档摸索
index
创建索引
PUT google
映射mapping(注意 mapping不能修改)
include_type_name,请求体中是否包含type,高版本中会移除type
Elasticsearc 6.x以后不再支持mapping下多个type,并且 6.x 版本type默认都是 _doc,7.0以后版本将会删除type
PUT /
PUT google/user/_mapping?include_type_name=true
{
"user": {
"properties": {
"name": {
"type": "text"
},
"user_name": {
"type": "keyword"
},
"email": {
"type": "keyword"
}
}
}
}
PUT /
PUT google/_mapping
{
"properties": {
"name": {
"type": "text"
},
"user_name": {
"type": "keyword"
},
"email": {
"type": "keyword"
}
}
}
创建索引+映射mapping
PUT /
PUT twitter?include_type_name=true
{
"mappings": {
"user": {
"properties": {
"name": {
"type": "text"
},
"user_name": {
"type": "keyword"
},
"email": {
"type": "keyword"
}
}
}
}
}
PUT /
PUT weibo
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"user_name": {
"type": "keyword"
},
"email": {
"type": "keyword"
}
}
}
}
删除索引
DELETE google
Document
创建文档
PUT /
PUT twitter/user/kimchy
{
"name": "Shay Banon",
"user_name": "kimchy",
"email": "shay@kimchy.com"
}
PUT /
PUT twitter/_doc/sharry
{
"name": "Shay sharry",
"user_name": "sharry",
"email": "shay@sharry.com"
}
修改文档
POST /
POST twitter/_update/sharry
{
"doc": {
"name": "Shay sharry3"
}
}
删除文档
DELETE /
DELETE /twitter/user/kimchy
DELETE /
DELETE /twitter/_doc/sharry
查询文档
根据id查询
GET /
GET /twitter/user/kimchy
GET /
GET /twitter/_doc/sharry
根据queryString查询
POST /
POST /twitter/user/_search
{
"query": {
"query_string": {
"default_field": "user_name",
"query": "sharry1"
}
}
}
POST /
POST /twitter/_search
{
"query": {
"query_string": {
"default_field": "user_name",
"query": "sharry1"
}
}
}
根据term查询
POST /
POST /twitter/user/_search
{
"query": {
"term": {
"query": "sharry1"
}
}
}
POST /
POST /twitter/_search
{
"query": {
"term": {
"query": "sharry1"
}
}
}
分词器
有三个字送给你,
一是“诚”,
二是“勤”,
三是“专”。
当你无比地想做成一件事,
愿意为它倾尽无数心血和努力时,
结果总不会太差。
一是“诚”,
二是“勤”,
三是“专”。
当你无比地想做成一件事,
愿意为它倾尽无数心血和努力时,
结果总不会太差。