———— Function Score ————
POST /blogs/_bulk
{"index":{"_id":1}}
{"title":"About popularity","content":"In this post we will talk about...","votes":0}
{"index":{"_id":2}}
{"title":"About popularity","content":"In this post we will talk about...","votes":100}
{"index":{"_id":3}}
{"title":"About popularity","content":"In this post we will talk about...","votes":100000}
POST /blogs/_search
{
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "popularity",
"fields": ["title","content"]
}
},
"field_value_factor": {
"field": "votes",
"modifier": "log1p",
"factor": 0.1
},
"boost_mode": "sum",
"max_boost": 3
}
}
}
———— 随机排序—————
POST /blogs/_search
{
"query": {
"function_score": {
"random_score": {
"seed": 3344445
}
}
}