I'm trying to add weight to some results from Elasticsearch.
I'm currently only filtering on an 'active' boolean to grab only the published items:
query: {
filtered: {
query: {
match: {
_all: params[:q]
}
},
filter: {
term: {
active: true
}
}
},
}
I now want to add weight to some of my models. For example, a Market should get a +2 boost. I was trying something like this: (search_type is a field on my results, it's basically the Rails model name)
POST _search
{
"query": {
"function_score": {
"query": {
"match": {
"_all": "hospitality"
}
},
"functions": [
{
"filter": {
"term": {
"active": true
}
}
},
{
"filter": {
"term": {
"search_type": "Market"
}
},
"weight": 2
}
]
}
}
}
However, that does not seem to work: "One entry in functions list is missing a function". So I added "weight": 1
to the active filter.. But now it says it can't parse.
I have no experience with ElasticSearch and the docs are quite confusing. I have also tried using a custom_filters_score
thing, but that doesn't seem to work for my version of ES (as described here: http://jontai.me/blog/2013/01/advanced-scoring-in-elasticsearch/). Another option I tried was combining a boolean query with must and should, but that returned zero results...
Not sure how to proceed. Some insights would be great.