@@ -41,7 +41,7 @@ public function update($models)
41
41
$ params ['body ' ][] = [
42
42
'update ' => [
43
43
'_id ' => $ model ->getKey (),
44
- '_index ' => $ this ->index ,
44
+ '_index ' => $ this ->getIndex ( $ model ) ,
45
45
'_type ' => $ model ->searchableAs (),
46
46
]
47
47
];
@@ -70,7 +70,7 @@ public function delete($models)
70
70
$ params ['body ' ][] = [
71
71
'delete ' => [
72
72
'_id ' => $ model ->getKey (),
73
- '_index ' => $ this ->index ,
73
+ '_index ' => $ this ->getIndex ( $ model ) ,
74
74
'_type ' => $ model ->searchableAs (),
75
75
]
76
76
];
@@ -121,7 +121,7 @@ public function paginate(Builder $builder, $perPage, $page)
121
121
protected function performSearch (Builder $ builder , array $ options = [])
122
122
{
123
123
$ params = [
124
- 'index ' => $ this ->index ,
124
+ 'index ' => $ this ->getIndex ( $ builder -> model ) ,
125
125
'type ' => $ builder ->model ->searchableAs (),
126
126
'body ' => [
127
127
'query ' => [
@@ -195,4 +195,19 @@ public function getTotalCount($results)
195
195
{
196
196
return $ results ['hits ' ]['total ' ];
197
197
}
198
+
199
+ /**
200
+ * Get the `index` name for the model.
201
+ * @param \Illuminate\Database\Eloquent\Model $model
202
+ * @return string [description]
203
+ */
204
+ private function getIndex ($ model = null )
205
+ {
206
+ $ method = 'getElasticsearchIndexName ' ;
207
+ if (!$ model || !method_exists ($ model , $ method )) {
208
+ return $ this ->index ;
209
+ }
210
+
211
+ return $ model ->$ method ();
212
+ }
198
213
}
0 commit comments