How to covert this elastic search functional score query to java API

后端 未结 1 1711
旧巷少年郎
旧巷少年郎 2021-01-22 10:43

How to convert the below ES query to Java API? I am using elastic search 2.3.3

 GET /schema_name/_search
 {
\"from\": 0,
\"size\": 200,
\"query\": {
    \"functi         


        
相关标签:
1条回答
  • 2021-01-22 10:59

    Achieved it as below using the java API

    FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders
                        .functionScoreQuery(queryBuilder)
                        .setMinScore(0f)
                        .maxBoost(50f)
                        .scoreMode("max")
                        .boostMode(CombineFunction.REPLACE);
    
                for (String alertCode : ruleCodesLowerCase) {
                    if(alertPriorityMap.get(alertCode.toUpperCase()) != null){
                        functionScoreQueryBuilder.add(QueryBuilders.termQuery(AlertESEnum.ALERT_CODE_FIELD.value(), 
                                alertCode), ScoreFunctionBuilders.weightFactorFunction((AlertPriority.intValue(alertPriorityMap.get(alertCode.toUpperCase()).getPriority()))));
                    }
                }
    
    0 讨论(0)
提交回复
热议问题