在弹性搜索中的should子句查询中获得最高分

时间:2016-05-30 15:17:23

标签: elasticsearch

我有一个带有should子句的多匹配查询。查询的目的是获取包含jdk或java或两者的所有结果。查询如下

{
"fields": [
    "id",
    "name"
],
"query": {
    "filtered": {
        "filter": {
            "bool": {
                "should": [
                    {
                        "term": {
                            "city": "12018206"
                        }
                    }
                ]
            }
        },
        "query": {
            "bool": {
                "should": [
                    {
                        "multi_match": {
                            "query": "jdk",
                            "fields": [
                                "name^6",
                                "description^3"
                            ],
                            "tie_breaker": 0.3,
                            "type": "best_fields",
                            "boost": 10
                        }
                    },
                    {
                        "multi_match": {
                            "query": "java",
                            "fields": [
                                "name^6",
                                "description^3"
                            ],
                            "tie_breaker": 0.3,
                            "type": "best_fields",
                            "boost": 10
                        }
                    }
                ]
            }
        }
    }
}}

此查询生成的最终得分是should子句中每个项目的得分平均值。我想要的是在should子句中每个项目获得的最大分数。

任何人都可以告诉我需要做出哪些改变。

由于

1 个答案:

答案 0 :(得分:3)

Dis Max Query应该有助于实现这一目标

示例:

{ 
"fields": [
    "id",
    "name"
],
"query": {
    "filtered": {
        "filter": {
            "bool": {
                "should": [
                    {
                        "term": {
                            "city": "12018206"
                        }
                    }
                ]
            }
        },
        "query": {
            "dis_max": {
                "queries": [
                    {
                        "multi_match": {
                            "query": "jdk",
                            "fields": [
                                "name^6",
                                "description^3"
                            ],
                            "tie_breaker": 0.3,
                            "type": "best_fields",
                            "boost": 10
                        }
                    },
                    {
                        "multi_match": {
                            "query": "java",
                            "fields": [
                                "name^6",
                                "description^3"
                            ],
                            "tie_breaker": 0.3,
                            "type": "best_fields",
                            "boost": 10
                        }
                    }
                ]
            }
        }
    }
}
}
相关问题