GeekIBLi

elasticsearch操作索引

2021-07-05

创建索引

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
PUT customer
{
"mappings":{
"properties":{
"id": {
"type": "long"
},
"name": {
"type": "text"
},
"email": {
"type": "text"
},
"order_id": {
"type": "long"
},
"order_serial": {
"type": "text"
},
"order_time": {
"type": "date"
},
"customer_order":{
"type":"join",
"relations":{
"customer":"order"
}
}
}
}
}

查看索引的mapping

GET yj_visit_data/_mapping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"yj_visit_data" : {
"mappings" : {
"properties" : {
"_class" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"article" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}

查询所有

GET yj_visit_data/_search

1
2
3
4
5
{
"query": {
"match_all": {}
}
}

删除所有

POST yj_visit_data/_delete_by_query

1
2
3
4
5
6
{
"query": {
"match_all": {
}
}
}

通过文章删除

POST yj_visit_data/_delete_by_query

1
2
3
4
5
6
7
{
"query": {
"match": {
"article.keyword": "2019/01/3"
}
}
}

根据文章查询

GET yj_visit_data/_search

1
2
3
4
5
6
7
8
{
"query": {
"match": {
"article.keyword": "2019/01/3"
}
}
}

修改索引

1
2
3
4
POST customer/_doc/1
{
"name":"2"
}