gpt4 book ai didi

python - 如何在ElasticSearch DSL python中创建Decay函数

转载 作者:行者123 更新时间:2023-12-03 00:59:41 24 4
gpt4 key购买 nike

我正在使用elasticsearch-dsl/2.0.0查询Elastic Search

 "linear": {
"date": {
"origin": "now",
"scale": "10d",
"offset": "5d",
"decay" : 0.5
}
}

https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-function-score-query.html#function-decay

如何使用elasticsearch-dsl构造线性函数查询

最佳答案

尝试以下查询

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, query

client = Elasticsearch()

s = Search(using=client)

function_score_query = query.Q(
'function_score',
query=query.Q('match', your_field='your_query'),
functions=[
query.SF('linear',date={"origin":"now","scale":"10d",
"offset":"5d", "decay":0.5})
]
)

如果打印 function_score_query.to_dict(),您将得到
{
'function_score': {
'query': {
'match': {
'your_field': 'your_query'
}
},
'functions': [{
'linear': {
'date': {
'origin': 'now',
'decay': 0.5,
'scale': '10d',
'offset': '5d'
}
}
}]
}
}

您可以检查github上的 test cases,以了解如何在DSL中使用功能得分查询

关于python - 如何在ElasticSearch DSL python中创建Decay函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39900211/

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