# Query score calculation algorithm for multiple scoring option given in query

**URL:** <https://discuss.elastic.co/t/query-score-calculation-algorithm-for-multiple-scoring-option-given-in-query/15489>\
**Category:** Elasticsearch\
**Created:** [January 30, 2014, 6:21am UTC](https://discuss.elastic.co/t/query-score-calculation-algorithm-for-multiple-scoring-option-given-in-query/15489 "2014-01-30T06:21:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [January 30, 2014, 6:21am UTC](https://discuss.elastic.co/t/query-score-calculation-algorithm-for-multiple-scoring-option-given-in-query/15489/1 "2014-01-30T06:21:25Z")

</div>

Hi All,

I have a following query, which I need to understand, How the scoring  
calculations are taking place here

the query is :

{

"query": {  
"custom\_filters\_score": {  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"should": [  
{  
"has\_child": {  
"type": "child\_GeoCountry",  
"score\_type": "sum",  
"query": {  
"constant\_score": {  
"query": {  
"term": {  
"rel": "rating\_fan"  
}  
}  
}  
}  
}  
},  
{  
"has\_child": {  
"type": "child\_GeoState",  
"score\_type": "sum",  
"query": {  
"constant\_score": {  
"query": {  
"term": {  
"rel": "rating\_fan"  
}  
}  
}  
}  
}  
},  
{  
"has\_child": {  
"type": "child\_GeoWorld",  
"score\_type": "sum",  
"query": {  
"constant\_score": {  
"query": {  
"term": {  
"rel": "rating\_fan"  
}  
}  
}  
}  
}  
},  
{  
"has\_child": {  
"type": "child\_GeoCity",  
"score\_type": "sum",  
"query": {  
"constant\_score": {  
"query": {  
"term": {  
"rel": "rating\_fan"  
}  
}  
}  
}  
}  
},  
{  
"has\_child": {  
"type": "child\_GeoNeighborhood",  
"score\_type": "sum",  
"query": {  
"constant\_score": {  
"query": {  
"term": {  
"rel": "rating\_fan"  
}  
}  
}  
}  
}  
}  
]  
}  
},  
"filter": {  
"or": [  
{  
"term":{  
"geo\_guid" : 23456  
}  
},  
{  
"term":{  
"user\_guid" : 87688  
}  
}  
]  
}  
}  
}  
]  
}  
}  
},  
"filters": [  
{  
"filter": {  
"term": {  
"subtype": "GeoNeighborhood"  
}  
},  
"script": 1000  
},  
{  
"filter": {  
"term": {  
"subtype": "GeoCity"  
}  
},  
"script": 2000  
},  
{  
"filter": {  
"term": {  
"subtype": "GeoState"  
}  
},  
"script": 3000  
},  
{  
"filter": {  
"term": {  
"subtype": "GeoCountry"  
}  
},  
"script": 4000  
}  
],  
"score\_mode": "total"  
}  
},  
"sort": {  
"\_score": {  
"order": "desc"  
}  
},  
"size": 10  
}

Now what this query was designed for is to find all of the documents having  
given "geo\_guid" or user\_guid, but they should be sorted by the number of  
child each document have. I have multiple child types, so I used should  
clause. i but the sorting's priority should be, the country entities  
should be listed first, they should be sorted by number of child doc they  
have, then states entities should come, and within the single bunch all  
states should be sorted by number of child doc they have and so on.. This  
was my requirement. But when I created the above query, the results are  
messed. Country, states and cities all are showing mixed.

I wanted to have the following output

country1 -- 10 children  
country2 -- 7 children  
country3 -- 3 children  
state1 -- 15 children  
state2 -- 10 children  
state 3 -- 8 children  
city1 -- 6 children  
city2 -- 2 children  
city3 -- 0 child

etc.

So I need to understand, what section is calculating first scoring, which  
comes after, and How the total score is being aggregated, and How I can  
change the behave as It seems to me like the first score is being  
multiplied internally to other to give total score, and I do not want this.

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ba77823e-784a-41f3-98f7-d2ed8ca569fc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ba77823e-784a-41f3-98f7-d2ed8ca569fc%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [January 30, 2014, 1:35pm UTC](https://discuss.elastic.co/t/query-score-calculation-algorithm-for-multiple-scoring-option-given-in-query/15489/2 "2014-01-30T13:35:38Z")

</div>

Narinder,

Can you try changing the script to boost for each of your filters.  
Something like this:

```
  "filters": [
    {
      "filter": {
        "term": {
          "subtype": "GeoNeighborhood"
        }
      },
      "boost": 1
    },
    {
      "filter": {
        "term": {
          "subtype": "GeoCity"
        }
      },
      "boost": 100
    },
    {
      "filter": {
        "term": {
          "subtype": "GeoState"
        }
      },
      "boost": 10000
    },
    {
      "filter": {
        "term": {
          "subtype": "GeoCountry"
        }
      },
      "boost": 1000000
    }
  ],

```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a48edebe-ffcd-44f8-863a-1ae917563aa5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a48edebe-ffcd-44f8-863a-1ae917563aa5%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [February 5, 2014, 6:36am UTC](https://discuss.elastic.co/t/query-score-calculation-algorithm-for-multiple-scoring-option-given-in-query/15489/3 "2014-02-05T06:36:53Z")

</div>

Thanks for the reply,But I have a lot of others scoring filters too which  
are further complicated. So I just saw the score reaching to infiinity, and  
sorting was a mess then. I can not use this, So my priority is to  
understand this logic instead of using this trick. I need to understand how  
these two scoring mechanism are being combinded to give final scoring.

On Thursday, 30 January 2014 19:05:38 UTC+5:30, Binh Ly wrote:

> Narinder,
> 
> Can you try changing the script to boost for each of your filters.  
> Something like this:
> 
> ```
> "filters": [
> {
> "filter": {
> "term": {
> "subtype": "GeoNeighborhood"
> }
> },
> "boost": 1
> },
> {
> "filter": {
> "term": {
> "subtype": "GeoCity"
> }
> },
> "boost": 100
> },
> {
> "filter": {
> "term": {
> "subtype": "GeoState"
> }
> },
> "boost": 10000
> },
> {
> "filter": {
> "term": {
> "subtype": "GeoCountry"
> }
> },
> "boost": 1000000
> }
> ],
> 
> ```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2641c9e2-1f4f-4be5-a8aa-1ddb0031c2c2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2641c9e2-1f4f-4be5-a8aa-1ddb0031c2c2%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:52am UTC](https://discuss.elastic.co/t/query-score-calculation-algorithm-for-multiple-scoring-option-given-in-query/15489/4 "2017-07-06T01:52:32Z")

</div>


