Skip to content

Commit bfc9836

Browse files
committed
fix readme
1 parent bb58004 commit bfc9836

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

readme.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Index and type names setted in query will override values the configuration file
7474

7575
ES::whereBetween("id", 100, 150)->get();
7676

77-
-
77+
>
7878
7979
// where not clause
8080

@@ -95,26 +95,26 @@ Index and type names setted in query will override values the configuration file
9595
ES::whereNotBetween("id", 100, 150)->get();
9696

9797

98-
-
98+
>
9999
100100
// Search the entire document
101101

102102
ES::search("bar")->get();
103103

104104

105-
-
105+
>
106106
107107
// Return only first record
108108

109109
ES::search("bar")->first();
110110

111-
-
111+
>
112112
113113
// Return only count
114114

115115
ES::search("bar")->count();
116116

117-
-
117+
>
118118
119119
// paginate results with per_page = 5
120120
@@ -125,7 +125,7 @@ Index and type names setted in query will override values the configuration file
125125
$documents->links();
126126

127127

128-
-
128+
>
129129
130130
// Executing elasticsearch raw queries
131131

@@ -145,7 +145,7 @@ Index and type names setted in query will override values the configuration file
145145
]);
146146

147147

148-
-
148+
>
149149
150150
// insert a new document
151151

@@ -159,8 +159,25 @@ Index and type names setted in query will override values the configuration file
159159

160160
[id is optional] if not specified, a unique hash key will be generated
161161

162-
163-
-
162+
163+
>
164+
165+
// Bulk insert a multiple of documents at once using multidimensional array of [id => data] pairs
166+
167+
ES::bulk(
168+
10 => [
169+
"title" => "Test document 1",
170+
"content" => "sample content 1"
171+
],
172+
11 => [
173+
"title" => "Test document 2",
174+
"content" => "sample content 2"
175+
],
176+
);
177+
178+
The two given documents will be inserted with its associated ids
179+
180+
>
164181
165182
// Update an existing document
166183
@@ -174,7 +191,7 @@ Index and type names setted in query will override values the configuration file
174191

175192
[id is required]
176193

177-
-
194+
>
178195
179196
// delete a document
180197

src/Query.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,36 @@ public function insert($data, $id = NULL)
687687

688688
}
689689

690+
/**
691+
* Insert a bulk of documents
692+
* @param $data multidimensional array of [id => data] pairs
693+
* @return object
694+
*/
695+
public function bulk($data)
696+
{
697+
698+
$params = [];
699+
700+
foreach ($data as $key => $value) {
701+
702+
$params["body"][] = [
703+
704+
'index' => [
705+
'_index' => $this->getIndex(),
706+
'_type' => $this->getType(),
707+
'_id' => $key
708+
]
709+
710+
];
711+
712+
$params["body"][] = $value;
713+
714+
}
715+
716+
return (object)$this->connection->bulk($params);
717+
718+
}
719+
690720
/**
691721
* Update a document
692722
* @param $data

0 commit comments

Comments
 (0)