Skip to content

Using multi indcies/types to search#108

Open
garveen wants to merge 3 commits into
elasticquent:masterfrom
Garveens-Forks:master
Open

Using multi indcies/types to search#108
garveen wants to merge 3 commits into
elasticquent:masterfrom
Garveens-Forks:master

Conversation

@garveen

@garveen garveen commented Aug 21, 2016

Copy link
Copy Markdown

Refs:
https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-index-multi-type.html
\Elasticsearch\Endpoints\AbstractEndpoint@setIndex
\Elasticsearch\Endpoints\AbstractEndpoint@setType

ElasticquentTrait.php has breaking change: The old data can NOT be searched until the indices be rebuilt.

@jgardezi

jgardezi commented Nov 7, 2016

Copy link
Copy Markdown

Can someone post an example of using this model. If you have to map multiple types of search results into models.

Kind regards,
Javed Gardezi

@garveen

garveen commented Nov 7, 2016

Copy link
Copy Markdown
Author

Can someone post an example of using this model. If you have to map multiple types of search results into models.

Just in case if you have to provide APIs such as "search anything" or "I don't know anything but the keyword"

@jgardezi

jgardezi commented Nov 8, 2016

Copy link
Copy Markdown

Just in case if you have to provide APIs such as "search anything" or "I don't know anything but the keyword"

@garveen Thank you for your reply.

Yes this is what I want. There are multiple types i.e books, author and users, etc. Its kind of global search.

Currently, I am using ElasticquentClientTrait directly to get the search results. But I want the results to be transformed into respective Eloquent models or some how I can parse the results into Transformers I have written using this library http://fractal.thephpleague.com/transformers/. For API consistency.

This is my current code

`
$client = $this->getElasticSearchClient();
$params = [
'index' => 'default',
];

$params['body']['from'] = ($page - 1)*$paginate;
$params['body']['size'] = $paginate;
$params['body']['query']['match'] = [
'_all' => $request->get('query')
];

$searchResults = $client->search($params); // this is manually being Transformed.
`

@garveen

garveen commented Nov 8, 2016

Copy link
Copy Markdown
Author

In this case, my code will be:

class Search extends \Illuminate\Database\Eloquent\Model
{
  use \Elasticquent\ElasticquentTrait;
}

$results = Search::searchByQuery([...]);
// $results contains instances, and they are have been transformed.
foreach($results as $result) {
 //...
}

@jgardezi

jgardezi commented Nov 9, 2016

Copy link
Copy Markdown

@garveen thank you man... I will give it go and let you know how it goes.

@jgardezi

Copy link
Copy Markdown

@garveen I have found the limitation of the above approach is that Search::searchByQuery looks for type searches. Well it has to search across other types i.e. books, author and users. Is their solution for types as well.

@garveen

garveen commented Nov 10, 2016

Copy link
Copy Markdown
Author

@jgardezi Oh it should be complexSearch... All methods with getBasicEsParams will not work with multi types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants