# Help with query design -- scoring

**URL:** <https://discuss.elastic.co/t/help-with-query-design-scoring/10006>\
**Category:** Elasticsearch\
**Created:** [December 9, 2012, 8:16pm UTC](https://discuss.elastic.co/t/help-with-query-design-scoring/10006 "2012-12-09T20:16:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crwe](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@Crwe](https://discuss.elastic.co/u/Crwe)\
**Post date:** [December 9, 2012, 8:16pm UTC](https://discuss.elastic.co/t/help-with-query-design-scoring/10006/1 "2012-12-09T20:16:28Z")

</div>

Hello, all!

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

> <https://gist.github.com/anonymous/4246795>

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!

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 10, 2012, 3:39pm UTC](https://discuss.elastic.co/t/help-with-query-design-scoring/10006/2 "2012-12-10T15:39:47Z")

</div>

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](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](https://gist.github.com/4246795)
> 
> 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!

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:00am UTC](https://discuss.elastic.co/t/help-with-query-design-scoring/10006/3 "2017-07-06T03:00:33Z")

</div>


