Skip to content
This repository was archived by the owner on Feb 5, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ After you've published the Laravel Scout package configuration:

...
'elasticsearch' => [
'index' => env('ELASTICSEARCH_INDEX', 'laravel'),
'index-prefix' => env('ELASTICSEARCH_INDEX_PREFIX', 'laravel'),
'hosts' => [
env('ELASTICSEARCH_HOST', 'http://localhost'),
],
Expand Down
21 changes: 12 additions & 9 deletions src/ElasticsearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ElasticsearchEngine extends Engine
*
* @var string
*/
protected $index;
protected $indexPrefix;

/**
* Elastic where the instance of Elastic|\Elasticsearch\Client is stored.
Expand All @@ -24,16 +24,19 @@ class ElasticsearchEngine extends Engine
*/
protected $elastic;

protected $type = 'doc';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future compatibility, consider defaulting $type to _doc instead of doc. See notes under Elasticsearch 7.x in the roadmap.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document mapping type name can't start with '_'.

Copy link

@IllyaMoskvin IllyaMoskvin Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting. My bad, it must be reserved for internal use. Thanks for giving it a shot.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



/**
* Create a new engine instance.
*
* @param \Elasticsearch\Client $elastic
* @return void
*/
public function __construct(Elastic $elastic, $index)
public function __construct(Elastic $elastic, $indexPrefix)
{
$this->elastic = $elastic;
$this->index = $index;
$this->indexPrefix = $indexPrefix;
}

/**
Expand All @@ -51,8 +54,8 @@ public function update($models)
$params['body'][] = [
'update' => [
'_id' => $model->getKey(),
'_index' => $this->index,
'_type' => $model->searchableAs(),
'_index' => $this->indexPrefix.$model->searchableAs(),
'_type' => $this->type
]
];
$params['body'][] = [
Expand All @@ -79,8 +82,8 @@ public function delete($models)
$params['body'][] = [
'delete' => [
'_id' => $model->getKey(),
'_index' => $this->index,
'_type' => $model->searchableAs(),
'_index' => $this->indexPrefix.$model->searchableAs(),
'_type' => $this->type
]
];
});
Expand Down Expand Up @@ -133,8 +136,8 @@ public function paginate(Builder $builder, $perPage, $page)
protected function performSearch(Builder $builder, array $options = [])
{
$params = [
'index' => $this->index,
'type' => $builder->index ?: $builder->model->searchableAs(),
'index' => $this->indexPrefix.$builder->model->searchableAs(),
'type' => $this->type,
'body' => [
'query' => [
'bool' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ElasticsearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function boot()
return new ElasticsearchEngine(ElasticBuilder::create()
->setHosts(config('scout.elasticsearch.hosts'))
->build(),
config('scout.elasticsearch.index')
config('scout.elasticsearch.index-prefix')
);
});
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ElasticsearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function test_update_adds_objects_to_index()
[
'update' => [
'_id' => 1,
'_index' => 'scout',
'_type' => 'table',
'_index' => 'scouttable',
'_type' => 'doc',
]
],
[
Expand All @@ -41,8 +41,8 @@ public function test_delete_removes_objects_to_index()
[
'delete' => [
'_id' => 1,
'_index' => 'scout',
'_type' => 'table',
'_index' => 'scouttable',
'_type' => 'doc',
]
],
]
Expand All @@ -56,8 +56,8 @@ public function test_search_sends_correct_parameters_to_elasticsearch()
{
$client = Mockery::mock('Elasticsearch\Client');
$client->shouldReceive('search')->with([
'index' => 'scout',
'type' => 'table',
'index' => 'scouttable',
'type' => 'doc',
'body' => [
'query' => [
'bool' => [
Expand Down