gpt4 book ai didi

ruby-on-rails - Elasticsearch日期衰减函数,Rails

转载 作者:行者123 更新时间:2023-12-02 23:29:37 28 4
gpt4 key购买 nike

我正在做一个简单的查询,包含多个字段,并尝试根据给定文档的存在天数来应用衰减函数。以下查询是我的尝试:

    {
query: {
function_score:{
query: {
multi_match: {
query: query,
fields: ['name', 'location']
},
functions: [{
gauss: {
created_at: {
origin: 'now',
scale: '1d',
offset: '2d',
decay: 0.5
}
}
}]
}
}
}
}

使用以下映射:
mappings dynamic: 'false' do
indexes :name, analyzer: 'english'
indexes :location, analyzer: 'english'
indexes :created_at, type: 'date'
end

给出以下错误:

[400] {"error":{"root_cause":[{"type":"query_parsing_exception","reason":"No query registered for [gauss]","index":"people","line":1,"col":143}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query_fetch","grouped":true,"failed_shards":[{"shard":0,"index":"jobs","node":"abcdefgZq1PMsd882foA","reason":{"type":"query_parsing_exception","reason":"No query registered for [gauss]","index":"people","line":1,"col":143}}]},"status":400}

最佳答案

functions需要上一层,仅在function_score内部而不是query内部,如下所示:

{
query: {
function_score:{
functions: [{
gauss: {
created_at: {
origin: 'now',
scale: '1d',
offset: '2d',
decay: 0.5
}
}
}],
query: {
multi_match: {
query: query,
fields: ['name', 'location']
}
}
}
}
}

关于ruby-on-rails - Elasticsearch日期衰减函数,Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37900181/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com