Query score calculation algorithm for multiple scoring option given in query


(narinder.izap) #1

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.
To view this discussion on the web visit 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.


(Binh Ly) #2

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.
To view this discussion on the web visit 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.


(narinder.izap) #3

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.
To view this discussion on the web visit 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.


(system) #4