ElasticSearch 自定義排序處理


使用function_score進行分組處理,利用分組函數script_score進行自定義分值處理,

注意:使用script功能需要在配置中打開腳本功能:

 script.inline: on  
 script.indexed: on
 script.engine.groovy.inline.aggs: on  
 script.file: on

下圖中的查詢表示,查詢termid為1238218的記錄,或者displayname包含“寶寶”的記錄;

termid為1238218的記錄排序分人為設定為100,displayname等於“寶寶”的記錄分值設定為99,其他按照displaynamelen排序;

{
  "query": { "function_score": { "filter": { "bool": { "should": [ { "term": { "termid": "1238218" } }, { "match_phrase": { "displayname": "寶寶" } } ] } }, "functions": [ { "filter": { "term": { "termid": "1238218" } }, "weight": 100 }, { "filter": { "term": { "displayname": "寶寶" } }, "weight": 99 }, { "script_score": { "script": "_score + doc['level'].value" } } ], "score_mode": "first" } } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM