Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multi indcies/types to search #108

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

garveen
Copy link

@garveen garveen commented Aug 21, 2016

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
Copy link

jgardezi commented Nov 7, 2016

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
Copy link
Author

garveen commented Nov 7, 2016

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
Copy link

jgardezi commented Nov 8, 2016

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
Copy link
Author

garveen commented Nov 8, 2016

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
Copy link

jgardezi commented Nov 9, 2016

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

@jgardezi
Copy link

@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
Copy link
Author

garveen commented Nov 10, 2016

@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