-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_documents.php
116 lines (99 loc) · 2.52 KB
/
create_documents.php
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
109
110
111
112
113
114
115
116
<?php
require "bootstrap.php";
$index = 'laptops_searchly_php_sample';
$type = 'laptop';
$indexParams['index'] = $index;
// Delete index if exists
if ($client->indices()->exists($indexParams)) {
$client->indices()->delete($indexParams);
}
// Example Index Mapping
$mapping = array(
'_source' => array(
'enabled' => true
),
'properties' => array(
'title' => array(
'type' => 'text'
),
'price' => array(
'type' => 'double'
),
'cpu' => array(
'type' => 'keyword'
),
'core' => array(
'type' => 'integer'
),
'ram' => array(
'type' => 'keyword'
),
'hard_drive' => array(
'type' => 'keyword'
),
'url' => array(
'type' => 'keyword'
),
'brand' => array(
'type' => 'text'
)
)
);
$indexParams['body']['mappings']['laptop'] = $mapping;
// Create Index
$client->indices()->create($indexParams);
// Laptops
$laptop1 = array(
"title" => "ASUS K200MA-DS01T 11.6-Inch Touchscreen Laptop (Black)",
"price" => "293.00",
"cpu" => "1.86 GHz Intel Celeron",
"core"=> 2,
"ram" => "8 GB",
"hard_drive" => "500 GB",
"url" => "http://www.amazon.com/K200MA-DS01T-11-6-Inch-Touchscreen-Laptop-Black/dp/B00HZT1T5E",
"brand"=> "Asus"
);
$laptop2 = array(
"title" => "Dell Inspiron 11.6-Inch Touchscreen Laptop (i3137-5003sLV)",
"price"=> "353.99",
"cpu" => "1.7 GHz Pentium 3556U",
"core" => 2,
"ram" => "4 GB",
"hard_drive" => "500 GB",
"url" => "http://www.amazon.com/Dell-Inspiron-11-6-Inch-Touchscreen-i3137-5003sLV/dp/B00I7PAXVG",
"brand" => "Dell"
);
$laptop3 = array (
"title" => "ASUS ROG G750JM-DS71 17.3-inch Gaming Laptop, GeForce GTX 860M Graphics",
"price" => "1278.99",
"cpu" => "3.4 GHz Core i7-4700HQ",
"core" => 4,
"ram" => "12 GB",
"hard_drive" => "1 TB",
"brand" => "Asus",
"url" => "http://www.amazon.com/G750JM-DS71-17-3-inch-Gaming-GeForce-Graphics/dp/B00IKF2H12"
);
// Document addition
$params = array();
$params['body'] = $laptop1;
$params['index'] = $index;
$params['type'] = $type;
$client->index($params);
$params = array();
$params['body'] = $laptop2;
$params['index'] = $index;
$params['type'] = $type;
$client->index($params);
$params = array();
$params['body'] = $laptop3;
$params['index'] = $index;
$params['type'] = $type;
$client->index($params);
?>
<?php include("layout/head.php"); ?>
<h2>Operation Result</h2>
<div>
3 Laptops are indexed
</div>
</hr>
<?php include("layout/footer.php"); ?>