Using multi indcies/types to search#108
Conversation
|
Can someone post an example of using this model. If you have to map multiple types of search results into models. Kind regards, |
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 ` $params['body']['from'] = ($page - 1)*$paginate; $searchResults = $client->search($params); // this is manually being Transformed. |
|
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) {
//...
} |
|
@garveen thank you man... I will give it go and let you know how it goes. |
|
@garveen I have found the limitation of the above approach is that Search::searchByQuery looks for type |
|
@jgardezi Oh it should be |
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.