Skip to content

Instantly share code, notes, and snippets.

@coler
Forked from nickhoffman/1_setup.txt
Created February 6, 2012 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coler/4a446763fa0c3d6c2fb0 to your computer and use it in GitHub Desktop.
Save coler/4a446763fa0c3d6c2fb0 to your computer and use it in GitHub Desktop.
Why does the "boost" not affect the score?
## In the 2 queries below, the documents have the same score, despite the 2nd query having a boost.
curl -X DELETE 'localhost:9200/test?pretty=1'
curl -X POST 'localhost:9200/test/foo?pretty=1' -d '{ name: "Nick Hoffman" }'
curl -X POST 'localhost:9200/test/foo?pretty=1' -d '{ name: "John Smith" }'
curl -X POST 'localhost:9200/test/foo?pretty=1' -d '{ name: "Nick Other" }'
curl -X POST 'localhost:9200/test/_refresh?pretty=1'
curl 'localhost:9200/test/foo/_search?pretty=1&explain=0' -d '{
"query":{
"dis_max":{
"queries":[
{ "text": { "name": { "query": "Nick" } } }
]
}
}
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.625,
"hits" : [ {
"_index" : "test",
"_type" : "foo",
"_id" : "_BkZVgcnSOyHPwlovRQ8MQ",
"_score" : 0.625, "_source" : { name: "Nick Hoffman" }
}, {
"_index" : "test",
"_type" : "foo",
"_id" : "CQTtPq7MQxan5mWXvZ6OuQ",
"_score" : 0.625, "_source" : { name: "Nick Other" }
} ]
}
}
curl 'localhost:9200/test/foo/_search?pretty=1&explain=0' -d '{
"query":{
"dis_max":{
"queries":[
{ "text": { "name": { "query": "Nick", "boost": 10 } } }
]
}
}
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.625,
"hits" : [ {
"_index" : "test",
"_type" : "foo",
"_id" : "_BkZVgcnSOyHPwlovRQ8MQ",
"_score" : 0.625, "_source" : { name: "Nick Hoffman" }
}, {
"_index" : "test",
"_type" : "foo",
"_id" : "CQTtPq7MQxan5mWXvZ6OuQ",
"_score" : 0.625, "_source" : { name: "Nick Other" }
} ]
}
}
curl 'localhost:9200/test/foo/_search?pretty=1&explain=0' -d '{
"query":{
"dis_max":{
"queries":[
{ "custom_score" : { "query" : { "text": { "name": { "query": "Nick" } } }, "script" : "_score", "boost" : 10 } }
]
}
}
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 6.25,
"hits" : [ {
"_index" : "test",
"_type" : "foo",
"_id" : "_BkZVgcnSOyHPwlovRQ8MQ",
"_score" : 6.25, "_source" : { name: "Nick Hoffman" }
}, {
"_index" : "test",
"_type" : "foo",
"_id" : "CQTtPq7MQxan5mWXvZ6OuQ",
"_score" : 6.25, "_source" : { name: "Nick Other" }
} ]
}
}
curl 'localhost:9200/test/foo/_search?pretty=1&explain=1' -d '{
"query": { "custom_score" : { "query" : { "text": { "name": { "query": "Nick", "boost" : 10 } } }, "script" : "_score", "boost" : 2 } }
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.25,
"hits" : [ {
"_shard" : 0,
"_node" : "dUt-dD8WSRuSdrQQrCcwEw",
"_index" : "test",
"_type" : "foo",
"_id" : "_BkZVgcnSOyHPwlovRQ8MQ",
"_score" : 1.25, "_source" : { name: "Nick Hoffman" },
"_explanation" : {
"value" : 1.25,
"description" : "custom score, product of:",
"details" : [ {
"value" : 0.625,
"description" : "script score function: product of:",
"details" : [ {
"value" : 0.625,
"description" : "fieldWeight(name:nick in 0), product of:",
"details" : [ {
"value" : 1.0,
"description" : "tf(termFreq(name:nick)=1)"
}, {
"value" : 1.0,
"description" : "idf(docFreq=2, maxDocs=3)"
}, {
"value" : 0.625,
"description" : "fieldNorm(field=name, doc=0)"
} ]
} ]
}, {
"value" : 2.0,
"description" : "queryBoost"
} ]
}
}, {
"_shard" : 0,
"_node" : "dUt-dD8WSRuSdrQQrCcwEw",
"_index" : "test",
"_type" : "foo",
"_id" : "CQTtPq7MQxan5mWXvZ6OuQ",
"_score" : 1.25, "_source" : { name: "Nick Other" },
"_explanation" : {
"value" : 1.25,
"description" : "custom score, product of:",
"details" : [ {
"value" : 0.625,
"description" : "script score function: product of:",
"details" : [ {
"value" : 0.625,
"description" : "fieldWeight(name:nick in 0), product of:",
"details" : [ {
"value" : 1.0,
"description" : "tf(termFreq(name:nick)=1)"
}, {
"value" : 1.0,
"description" : "idf(docFreq=2, maxDocs=3)"
}, {
"value" : 0.625,
"description" : "fieldNorm(field=name, doc=0)"
} ]
} ]
}, {
"value" : 2.0,
"description" : "queryBoost"
} ]
}
} ]
}
}
curl 'localhost:9200/test/foo/_search?pretty=1&explain=1' -d '{
"query": { "custom_score" : { "query" : { "text": { "name": { "query": "Nick", "boost" : 10 } } }, "script" : "_score", "boost" : 3 } }
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.8750002,
"hits" : [ {
"_shard" : 0,
"_node" : "dUt-dD8WSRuSdrQQrCcwEw",
"_index" : "test",
"_type" : "foo",
"_id" : "_BkZVgcnSOyHPwlovRQ8MQ",
"_score" : 1.8750002, "_source" : { name: "Nick Hoffman" },
"_explanation" : {
"value" : 1.8750002,
"description" : "custom score, product of:",
"details" : [ {
"value" : 0.62500006,
"description" : "script score function: product of:",
"details" : [ {
"value" : 0.62500006,
"description" : "weight(name:nick^10.0 in 0), product of:",
"details" : [ {
"value" : 1.0000001,
"description" : "queryWeight(name:nick^10.0), product of:",
"details" : [ {
"value" : 10.0,
"description" : "boost"
}, {
"value" : 1.0,
"description" : "idf(docFreq=2, maxDocs=3)"
}, {
"value" : 0.10000001,
"description" : "queryNorm"
} ]
}, {
"value" : 0.625,
"description" : "fieldWeight(name:nick in 0), product of:",
"details" : [ {
"value" : 1.0,
"description" : "tf(termFreq(name:nick)=1)"
}, {
"value" : 1.0,
"description" : "idf(docFreq=2, maxDocs=3)"
}, {
"value" : 0.625,
"description" : "fieldNorm(field=name, doc=0)"
} ]
} ]
} ]
}, {
"value" : 3.0,
"description" : "queryBoost"
} ]
}
}, {
"_shard" : 0,
"_node" : "dUt-dD8WSRuSdrQQrCcwEw",
"_index" : "test",
"_type" : "foo",
"_id" : "CQTtPq7MQxan5mWXvZ6OuQ",
"_score" : 1.8750002, "_source" : { name: "Nick Other" },
"_explanation" : {
"value" : 1.8750002,
"description" : "custom score, product of:",
"details" : [ {
"value" : 0.62500006,
"description" : "script score function: product of:",
"details" : [ {
"value" : 0.62500006,
"description" : "weight(name:nick^10.0 in 0), product of:",
"details" : [ {
"value" : 1.0000001,
"description" : "queryWeight(name:nick^10.0), product of:",
"details" : [ {
"value" : 10.0,
"description" : "boost"
}, {
"value" : 1.0,
"description" : "idf(docFreq=2, maxDocs=3)"
}, {
"value" : 0.10000001,
"description" : "queryNorm"
} ]
}, {
"value" : 0.625,
"description" : "fieldWeight(name:nick in 0), product of:",
"details" : [ {
"value" : 1.0,
"description" : "tf(termFreq(name:nick)=1)"
}, {
"value" : 1.0,
"description" : "idf(docFreq=2, maxDocs=3)"
}, {
"value" : 0.625,
"description" : "fieldNorm(field=name, doc=0)"
} ]
} ]
} ]
}, {
"value" : 3.0,
"description" : "queryBoost"
} ]
}
} ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment