Absolute newb here, so go easy!
I am wanting to build a better search for my shopping site, and I'm tinkering with elasticsearch right now. I'm trying to come up with a somewhat smarter "default" product search query that searches four fields, each weighted differently:
name (product name), weighted highest
search_words (list of keywords), medium weight
description (item copy), low weight
skuid (item number), lowest weight - needed in case the customer plugs in a SKU to the search field
But I also want to consider two other fields: sort_priority and creation_date
sort_priority is a value we use for "important" items that we want to show higher when browsing category. Since it denotes an item's importance, I want to factor it in to search somehow. 9999999 is the default, and anything lower is considered more important, with "1" being the most important.
creation_date is just that. It would be awesome to be able to weight newer items a bit higher.
My index has the following mappings:
mappings => { "product" => { properties => { "price" => {type => 'double'}, "origprice" => {type => 'double'}, "sort_priority" => {type => 'integer'}, "creation_date" => { type => "date", format => "YYYY-mm-dd" } } } }
Which I hope will give me the ability to use sort_priority and creation_date in the fashion I outlined.
This query seems to work for the matching:
"query" : { "multi_match" : { "query": "awesome product", "type": "best_fields", "fields": [ "name^10", "search_words^5", "description^2", "skuid^1" ] } }
But I can't figure out the scoring manipulation. I'd think something in this realm?
"query" : { "function_score": { "query" : { "multi_match" : { "query": "awesome product", "type": "best_fields", "fields": [ "name^10", "search_words^5", "description^2", "skuid^1" ] } } }, "functions" : [ "script_score" : { "script" : "_score * (1000000 - doc['sort_priority'].value)" } ] }
(though that doesn't factor in creation_date at all)
Any help or hints appreciated!