Skip to content

Instantly share code, notes, and snippets.

@stevepm
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevepm/f8ea0985276ab1f5235a to your computer and use it in GitHub Desktop.
Save stevepm/f8ea0985276ab1f5235a to your computer and use it in GitHub Desktop.
Elastic search query
settings index: {number_of_shards: 1} do
mappings dynamic: 'false' do
indexes :name, analyzer: 'standard', index_options: 'offsets'
indexes :description, analyzer: 'standard', index_options: 'offsets'
indexes :total_downloads, type: 'long'
end
end
def search(query)
__elasticsearch__.search(
{
from: 0,
size: 150,
query: {
filtered: {
query: {
bool: {
should: [
{function_score: {
query: {
multi_match: {
query: query,
fields: ['name^10', 'description'],
type: "phrase",
}
},
functions: [
script_score: {
script: "_score * doc['total_downloads'].value / 2**3.1"
}
],
score_mode: "sum"
}},
{term: {name:
{value: query,
boost: 2.0}}
}
]
}
},
filter: {
range: {
total_downloads: {
from: 1000
}
}
}
}
}
}
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment