Elastic::Model::SearchBuilder - An Elastic::Model specific subclass of ElasticSearch::SearchBuilder
version 0.51
Elastic::Model::SearchBuilder is a sub-class of ElasticSearch::SearchBuilder to add automatic handling of Elastic::Doc and Elastic::Model::UID values.
This document just explains the functionality that Elastic::Model::SearchBuilder adds.
For the full SearchBuilder docs, see ElasticSearch::SearchBuilder.
Consider this class (where MyApp::User is also an Elastic::Doc class):
MyApp::User
package MyApp::Comment; use Elastic::Doc; has 'user' => ( is => 'ro', isa => 'MyApp::User, ); has 'text' => ( is => 'ro', isa => 'Str', );
We can create a comment as follows:
$domain->create( comment => { text => 'I like Elastic::Model', user => $user, } );
The comment object would be stored in Elasticsearch as something like this:
comment
{ text => "I like Elastic::Model", user => { uid => { index => 'myapp', type => 'user', id => 'abcdefg', }, .... any other user fields.... } }
In order to search for any comments by user $user, you would need to do this:
$user
$view->type('comment') ->filterb( 'user.uid.index' => $user->uid->index, 'user.uid.type' => $user->uid->type, 'user.uid.id' => $user->uid->id, ) ->search;
With Elastic::Model::SearchBuilder, you can do it as follows:
$view->type('comment') ->filterb( user => $user ) ->search;
Or with the UID:
UID
$view->type('comment') ->filterb( user => $user->uid ) ->search;
This works for both queries and filters, eg:
$view->queryb ( user => $user )->search; $view->filterb( user => $user )->search;
You can use either the doc/object itself, or an Elastic::Model::UID object:
$uid = $user->uid; $view->queryb ( user => $uid )->search; $view->filterb( user => $uid )->search;
$view->queryb ( user => { '!=' => $user })->search; $view->filterb( user => { '!=' => $user })->search;
$view->queryb ( user => \@users )->search; $view->filterb( user => \@users )->search;
$view->queryb ( user => { '!=' => \@users })->search; $view->filterb( user => { '!=' => \@users })->search;
Clinton Gormley <drtech@cpan.org>
This software is copyright (c) 2015 by Clinton Gormley.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Elastic::Model, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Elastic::Model
CPAN shell
perl -MCPAN -e shell install Elastic::Model
For more information on module installation, please visit the detailed CPAN module installation guide.