Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 根据字段值添加查询时间权重/提升_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch 根据字段值添加查询时间权重/提升,elasticsearch,elasticsearch" /> elasticsearch 根据字段值添加查询时间权重/提升,elasticsearch,elasticsearch" />

elasticsearch 根据字段值添加查询时间权重/提升

elasticsearch 根据字段值添加查询时间权重/提升,elasticsearch,elasticsearch,我目前正在使用elasticsearch 2.4版,并希望根据我使用查询时间提升或权重调用的“类型”字段微调结果集 比如说 如果字段“type”的值为“shoots”,则添加权重或提升4 如果字段“type”的值为“Caravans”,则添加权重或提升3 从而使匹配查询字符串的船只出现在搜索结果中的商队之前 我发现到目前为止我读过的关于过滤器、函数和函数分数的文档非常复杂。如果有人能为我的场景提供一个例子,我将不胜感激。您应该使用常量评分查询和提升选项来确定优先级 { "query": {

我目前正在使用elasticsearch 2.4版,并希望根据我使用查询时间提升或权重调用的“类型”字段微调结果集

比如说

如果字段“type”的值为“shoots”,则添加权重或提升4

如果字段“type”的值为“Caravans”,则添加权重或提升3

从而使匹配查询字符串的船只出现在搜索结果中的商队之前


我发现到目前为止我读过的关于过滤器、函数和函数分数的文档非常复杂。如果有人能为我的场景提供一个例子,我将不胜感激。

您应该使用
常量评分查询和
提升
选项来确定优先级

{
  "query": {
    "bool": {
        "should": [
            {
                "constant_score": {
                    "boost": 4,
                    "query": {
                        "match": {
                            "description": "Boats"
                        }
                    }
                }
            },
            {
                "constant_score": {
                    "boost": 3,
                    "query": {
                        "match": {
                            "description": "Caravans"
                        }
                    }
                }
            }
        ]
    }
  }
}

您应该使用
constant_score
查询和
boost
选项来确定优先级

{
  "query": {
    "bool": {
        "should": [
            {
                "constant_score": {
                    "boost": 4,
                    "query": {
                        "match": {
                            "description": "Boats"
                        }
                    }
                }
            },
            {
                "constant_score": {
                    "boost": 3,
                    "query": {
                        "match": {
                            "description": "Caravans"
                        }
                    }
                }
            }
        ]
    }
  }
}

试试
constant\u score
querytanks,很棒的答案试试
constant\u score
querytanks,很棒的答案