ElasticSearch::Util - Util subs for ElasticSearch


ElasticSearch::Util provides various subs useful to other modules in ElasticSearch.

The only sub useful to users is "filter_keywords()", which can be exported.


    use ElasticSearch::Util qw(filter_keywords);

    my $filtered = filter_keywords($unfiltered)



This tidies up a string to be used as a query string in (eg) "search()" in ElasticSearch so that user input won't cause a search query to return an error.

It is not flexible at all, and may or may not be useful to you.

Have a look at ElasticSearch::QueryParser which gives you much more control over your query strings.

The current implementation does the following:

  • Removes any character which isn't a letter, a number, a space or -+'"*@._.

  • Removes and, or and not

  • Removes any - that doesn't have a space in front of it ( "foo -bar") is acceptable as it means 'foo' but not with 'bar'

  • Removes any space after a + or -

  • Removes any + or - which is not followed by a letter, number or a double quote

  • Removes any * that doesn't have at least 3 letters before it, ie we only allow wildcard searches on words with at least 3 characters

  • Closes any open double quotes

  • Removes leading and trailing whitespace



Copyright 2010 - 2011 Clinton Gormley.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.