-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlecture08.txt
109 lines (98 loc) · 2.13 KB
/
lecture08.txt
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Index Settings and Mappings (part 1)
Step 1) check whether the customers index exists
HEAD customers
404 - Not Found
Step 2) Create the structure of this index
PUT /customers
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
},
"mappings": {}
}
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "customers"
}
Step 3) check the structure
GET /customers
{
"customers": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"creation_date": "1541715495045",
"number_of_shards": "2",
"number_of_replicas": "1",
"uuid": "hdd6Gwi-RrGCoU1Xoo46DA",
"version": {
"created": "6040299"
},
"provided_name": "customers"
}
}
}
}
Step 4) let's define the mappings, which tells what are the fields in the documents and their types
PUT /customers
{
"mappings": {
"online": {
"properties": {
"gender": {
"type": "text",
"analyzer": "standard"
},
"age": {
"type": "integer"
},
"total_spent": {
"type": "float"
},
"is_new": {
"type": "boolean"
},
"name": {
"type": "text",
"analyzer": "standard"
}
}
}
},
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
}
}
{
"error": {
"root_cause": [
{
"type": "resource_already_exists_exception",
"reason": "index [customers/hdd6Gwi-RrGCoU1Xoo46DA] already exists",
"index_uuid": "hdd6Gwi-RrGCoU1Xoo46DA",
"index": "customers"
}
],
"type": "resource_already_exists_exception",
"reason": "index [customers/hdd6Gwi-RrGCoU1Xoo46DA] already exists",
"index_uuid": "hdd6Gwi-RrGCoU1Xoo46DA",
"index": "customers"
},
"status": 400
}
This error is because we already defined a structure.
We must delete the index before resubmitting a new structure.
DELETE /customers
{
"acknowledged": true
}
This is now the response after PUT the new /customers structure:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "customers"
}