Skip to content

Instantly share code, notes, and snippets.

@omarqureshi
Last active August 29, 2015 13:55
Show Gist options
  • Save omarqureshi/8729163 to your computer and use it in GitHub Desktop.
Save omarqureshi/8729163 to your computer and use it in GitHub Desktop.
def self.search(q, options={})
query = {
:query => {
:bool => {
:should => [
{:match => {:_all => q}},
{:match => {:mobile => {:query => q, :type => "phrase_prefix"}}}
]
}
}
}
res = $es.search(:index => INDEX_NAME,
:body => query)
res["hits"]["hits"].map do |hit|
attributes = hit["_source"]
attributes["id"] = hit["_id"]
OpenStruct.new(attributes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment