Range versus term boosting in Elastic Search

Hi,

I am struggling to make boosting work the way I want it to in Elastic
Search.

Let's say I have some profiles indexed containing gender, interests
and age, and let's say that I find it most relevant that the gender
matches, then the interest and the least important criterium is the
user's age. I was expecting the below query to result in an ordering
of the matching profiles according to the just mentioned principle,
but when I execute it I get some males first and then I get the female
Anna of the age 50 before the female Maria who likes cars... why
doesn't Maria get a higher score than Anna??

{
"query": {
"bool" : {
"should" : [
{ "term" : { "gender" : { "term": "male", "boost":
10.0 } } },
{ "term" : { "likes" : { "term": "cars", "boost" :
5.0 } } },
{ "range" : { "age" : { "from" : 50, "boost" :
1.0 } } }
],
"minimum_number_should_match" : 1
}
}
}

Hints will be greatly appreciated, thanks,
Stine

Hi Stine,

Is Anna a male ?

Just kidding !

Do you find Maria when you search only for cars ? Do you use default mapping ?
Did you try to activate explain to see how ES (Lucene) computes results scores ?

http://www.elasticsearch.org/guide/reference/api/search/explain.html

David.

Le 8 juin 2012 à 11:13, Stine stinesplace@gmail.com a écrit :

Hi,

I am struggling to make boosting work the way I want it to in Elastic
Search.

Let's say I have some profiles indexed containing gender, interests
and age, and let's say that I find it most relevant that the gender
matches, then the interest and the least important criterium is the
user's age. I was expecting the below query to result in an ordering
of the matching profiles according to the just mentioned principle,
but when I execute it I get some males first and then I get the female
Anna of the age 50 before the female Maria who likes cars... why
doesn't Maria get a higher score than Anna??

{
"query": {
"bool" : {
"should" : [
{ "term" : { "gender" : { "term": "male", "boost":
10.0 } } },
{ "term" : { "likes" : { "term": "cars", "boost" :
5.0 } } },
{ "range" : { "age" : { "from" : 50, "boost" :
1.0 } } }
],
"minimum_number_should_match" : 1
}
}
}

Hints will be greatly appreciated, thanks,
Stine

--
David Pilato
http://dev.david.pilato.fr/
Twitter : @dadoonet

Was just thinking that it might be useful if I posted the curl commands necessary to reproduce...

$ curl -XPUT http://localhost:9200/users/profile/1 -d '{ "nickname" : "bob", "gender" : "male", "age" : 48, "likes" : "airplanes" }'

$ curl -XPUT http://localhost:9200/users/profile/2 -d '{
"nickname" : "carlos",
"gender" : "male",
"age" : 24,
"likes" : "food"
}

$ curl -XPUT http://localhost:9200/users/profile/3 -d '{
"nickname" : "julio",
"gender" : "male",
"age" : 18,
"likes" : "ladies"
}

$ curl -XPUT http://localhost:9200/users/profile/4 -d '{
"nickname" : "maria",
"gender" : "female",
"age" : 25,
"likes" : "cars"
}

$ curl -XPUT http://localhost:9200/users/profile/5 -d '{
"nickname" : "anna",
"gender" : "female",
"age" : 50,
"likes" : "clothes"
}

$ curl -XGET http://localhost:9200/users/profile/_search -d '{
"query": {
"bool" : {
"should" : [
{ "term" : { "gender" : { "term": "male", "boost": 10.0 } } },
{ "term" : { "likes" : { "term": "cars", "boost" : 5.0 } } },
{ "range" : { "age" : { "from" : 50, "boost" : 1.0 } } }
],
"minimum_number_should_match" : 1
}
}
}'

Thanks! I tried to add the explain, but must admit I did not get much out of it ;D Hmm..