Elasticsearch query parser

- I can search “London” and it will return everyone with “London”
- And then a complex example could be a boolean search such as: ((('London' OR 'Paris') OR 'Madrid') AND 'Venture Capital') NOT VC
Hot to install
Add this line to your application's Gemfile:
gem "elasticsearch_query_parser"
And then execute:
$ bundle
How to use
require "elasticsearch_query_parser"
ElasticsearchQueryParser.parse_query("London")
ElasticsearchQueryParser.parse_query("London Madrid")
ElasticsearchQueryParser.parse_query("London OR Madrid")
ElasticsearchQueryParser.parse_query("(London OR Madrid) AND Paris")
ElasticsearchQueryParser.parse_query("(((London OR Paris) OR Madrid) AND 'Venture Capital') NOT VC")
ElasticsearchQueryParser.parse_query("Paris AND (London OR Madrid)")
ElasticsearchQueryParser.parse_query("VC AND ('Venture Capital' AND (Madrid OR (Paris AND London)))")
ElasticsearchQueryParser.parse_query("((London OR Madrid) NOT VC) NOT 'Venture Capital'")
How to change Elastic field name
By default #parse_query
generates elastic query with text
attribute. You can customize field name via config:
ElasticsearchQueryParser.configure do |config|
config.elastic_field_name = "title"
end
ElasticsearchQueryParser.parse_query("London")