Help with query design -- scoring

Hello, all!

Following the recommendations for getting help, I created a minimal
gist with my problem:

In short, each documents contains a subset of possible tags, for
example "tags": ["red", "green", "blue"]. I want to retrieve documents
matching only specific tags (for example, only either "red" or
"blue"). A filtered query seems to do the job here.

The twist is, I want the documents that matched "red" ranked higher
than documents that matched just "blue". So basically score
differently based on the "tags" filters.

In the documentation, I found something called "custom_filters_score",
but I can't get it to work (see gist).

What is the best way to achieve this? Help and comments on crafting
this query are much appreciated!

--

The filters in the custom_filters_score filter don't affect what's
returned, they only affect scoring. I you want to retrieve only documents
that match specific tags, you need to move your term queries into bool
query. For example:

curl -XPOST http://localhost:9200/test/_search -d '{
"query": {
"bool": {
"should": [
{
"term": {
"tags": {
"value": "red",
"boost": 2
}
}
}, {
"term": {
"tags": {
"value": "blue",
"boost": 1
}
}
}
],
"must": [
{
"query_string": {
"fields": [
"title"
],
"query": "colour",
"default_operator": "AND"
}
}
],
"minimum_number_should_match": 1
}
}
}'

On Sunday, December 9, 2012 3:16:28 PM UTC-5, Crwe wrote:

Hello, all!

Following the recommendations for getting help, I created a minimal
gist with my problem:

gist:4246795 · GitHub

In short, each documents contains a subset of possible tags, for
example "tags": ["red", "green", "blue"]. I want to retrieve documents
matching only specific tags (for example, only either "red" or
"blue"). A filtered query seems to do the job here.

The twist is, I want the documents that matched "red" ranked higher
than documents that matched just "blue". So basically score
differently based on the "tags" filters.

In the documentation, I found something called "custom_filters_score",
but I can't get it to work (see gist).

What is the best way to achieve this? Help and comments on crafting
this query are much appreciated!

--