Announcing ElasticSearch::SearchBuilder
In Perl, we like to put important things first, so the ElasticSearch query language has always felt a bit wrong to me. For instance, to find docs where the content
field contains the text keywords
:
# op field value
{ text => { content => 'keywords' } }
To me, the important part of this is the field that we’re operating on, so this feels more natural:
# field op value
{ content => { text => 'keywords' }}
So, in the spirit of SQL::Abstract I am proud to announce ElasticSearch::SearchBuilder, which is tightly integrated into the latest ElasticSearch.pm version 0.38.
Any method which takes a query
or filter
param (eg search() now also accepts a queryb
or filterb
parameter instead, whose value will be parsed via SearchBuilder:
Do a full text search of the _all
field for 'my keywords'
:
$es->search( queryb=> 'my keywords' );
Find docs whose title field contains the text apple
but not orange
, whose status
field contains the value active
:
$es->search(
queryb => {
title => {
'=' => 'apple',
'!=' => 'orange'
},
-filter => {
status => 'active'
}
}
)