世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :boost有什么特点?
答 :
问 :boost如何使用?
答 :
# boost
PUT /boost_test
{
"mappings" : {
"properties" : {
"title" : {"type" : "text"},
"content" : {"type" : "text"}
}
}
}
# 索引
POST /boost_test/_doc/1
{
"title" : "hello good me",
"content" : "hello good me"
}
POST /boost_test/_doc/2
{
"title" : "good hello",
"content" : "this is a good me"
}
POST /boost_test/_doc/3
{
"title" : "good me",
"content" : "hello good me"
}
POST /boost_test/_doc/4
{
"title" : "hello me",
"content" : "hello good me"
}
# 搜索
GET /boost_test/_search
{
"query" : {
"bool": {
"should" : [
{
"match" : {
"title": {
"query" : "good",
"boost" : 2
}
}
},
{
"match": {
"content" : {
"query" : "hello",
"boost" : 1
}
}
}
]
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.1261322,
"hits" : [
{
"_index" : "boost_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.1261322,
"_source" : {
"title" : "good me",
"content" : "hello good me"
}
},
{
"_index" : "boost_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0065613,
"_source" : {
"title" : "hello good me",
"content" : "hello good me"
}
},
{
"_index" : "boost_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.7473189,
"_source" : {
"title" : "good hello",
"content" : "this is a good me"
}
},
{
"_index" : "boost_test",
"_type" : "_doc",
"_id" : "4",
"_score" : 0.3788134,
"_source" : {
"title" : "hello me",
"content" : "hello good me"
}
}
]
}
}
# 搜索
GET /boost_test/_search
{
"query" : {
"bool": {
"should" : [
{
"match" : {
"title": {
"query" : "good",
"boost" : 1
}
}
},
{
"match": {
"content" : {
"query" : "hello",
"boost" : 2
}
}
}
]
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.1312863,
"hits" : [
{
"_index" : "boost_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.1312863,
"_source" : {
"title" : "good me",
"content" : "hello good me"
}
},
{
"_index" : "boost_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0715008,
"_source" : {
"title" : "hello good me",
"content" : "hello good me"
}
},
{
"_index" : "boost_test",
"_type" : "_doc",
"_id" : "4",
"_score" : 0.7576268,
"_source" : {
"title" : "hello me",
"content" : "hello good me"
}
},
{
"_index" : "boost_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.37365946,
"_source" : {
"title" : "good hello",
"content" : "this is a good me"
}
}
]
}
}