Last active
August 29, 2015 14:02
-
-
Save stevepm/f8ea0985276ab1f5235a to your computer and use it in GitHub Desktop.
Elastic search query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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