NAME
Data::AnyXfer::Elastic::DSL
DESCRIPTION
Data::AnyXfer::Elastic::DSL contains helpful methods to help reduce the verbosity of Elasticsearch queries through its Domain Specific Language (DSL). These methods can be used in both filters and query clauses; adjusting additional Elasticsearch arguments accordingly.
Query DSL: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html
SYNOPSIS
use constant DSL => 'Data::AnyXfer::Elastic::DSL';
my $exists = DSL->exists('location');
my $match = DSL->match( 'name', 'George' );
my $match_phrase = DSL->match_phrase( 'Vonnegut', 'So it goes.' );
my $missing = DSL->missing('property_reference');
my $range = DSL->range( 'age', gte => 16, lte => 25 );
my $regexp = DSL->regexp( 'postcode_short', value => 'E.*' );
my $term = DSL->term( 'name', value => 'foxtons', boost => 1 );
my $terms = DSL->terms( 'office', values => [ 1, 2, 3 ] );
my $geo_bounding_box = DSL->geo_bounding_box(
'pin.location',
top_left => { lat => 50, lon => 0 },
bottom_right => { lat => 49, lon => -0.1 }
);
my $geo_distance = DSL->geo_distance(
'pin.location',
distance => '100km',
lat => 40,
lon => -70
);
my $geo_polygon = DSL->geo_polygon(
'pin.location',
points => [ [ -70, 40 ], [ -80, 30 ], [ -90, 20 ] ],
_cache => 1,
);
my $geo_shape = DSL->geo_shape(
'pin.location',
"coordinates" : [
[ [[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]] ],
[ [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]] ]
],
type => 'multipolygon'
);
METHODS
Common Methods
range
match
regexp
geo_bounding_box
The are common methods that have the same interface( $field, %arguements ):
- field
-
Defines the field name to search by.
- arguements
-
This hash takes all optional Elasticsearch options such as boost and _cache; in addition to specific arguements for the filter/query clause.
exists
DSL->exists( $field );
Returns a exists clause.
geo_distance
DSL->geo_distance( $field, lat => 40, lon => 20, %es_args );
Returns a geo distance clause.
geo_polygon
DSL->term( $field, points => [...] %es_args );
Returns a geo polygon filter clause.
geo_shape
DSL->term( $field, coordinates => [...] %es_args );
Returns a geo shape filter clause.
match_phrase
DSL->match_phrase( $field, $phrase );
Returns a match_phrase clause.
missing
DSL->missing( $field );
Returns a field missing clause
term
DSL->term( $field, value => 'criteria', %es_args );
Returns a term clause.
terms
DSL->terms( $field, values => \@criteria, %es_args );
Returns a terms clause.
format_datetime
DSL->format_datetime('2001-10-02'); # returns 2001-10-02 23:59:59
DSL->format_datetime( Datetime->new );
DSL->format_datetime( london_now );
This method returns a datetime string in the format of yyyy-mm-dd hh:mm:ss for use in Elasticsearch queries. It accepts any DateTime object or a string in the format yyyy-mm-dd. Defaults to now().
COPYRIGHT
This software is copyright (c) 2019, Anthony Lucas.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.