"linear": {
"date": {
"origin": "now",
"scale": "10d",
"offset": "5d",
"decay" : 0.5
}
}
如何使用elasticsearch-dsl构建线性函数查询
答案 0 :(得分:1)
尝试以下查询
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中使用功能得分查询