我在记录模式中有一个字段distribution
,如下所示:
...
"distribution": {
"properties": {
"availability": {
"type": "keyword"
}
}
}
...
我想对distribution.availability == "ondemand"
比其他记录低的记录进行排名
我查看了Elasticsearchdocs,但找不到一种方法来降低这类记录在索引时间中的分数,使其在搜索结果中显得更低
我怎样才能做到这一点,任何指向相关源代码的指针也就足够了
更多信息:
在python客户端的帮助下,我在查询时间中完全省略了这些ondemand
记录,如下所示:
from elasticsearch_dsl.query import Q
_query = Q("query_string", query=query_string) & ~Q('match', **{'availability.keyword': 'ondemand'})
现在,我想包括这些记录,但我想把它们放在比其他记录低的位置
如果在索引时间中无法实现类似的功能,请建议如何使用python客户端在查询时间中实现
应用llermaly的建议后,python客户端查询如下所示:
boosting_query = Q(
"boosting",
positive=Q("match_all"),
negative=Q(
"bool", filter=[Q({"term": {"distribution.availability.keyword": "ondemand"}})]
),
negative_boost=0.5,
)
if query_string:
_query = Q("query_string", query=query_string) & boosting_query
else:
_query = Q() & boosting_query
EDIT2:elasticsearch-dsl-py版本的boosting查询
编辑:只需阅读你需要在索引时间完成的内容
Elasticsearch不推荐在5.0上增加索引时间 https://www.elastic.co/guide/en/elasticsearch/reference/7.11/mapping-boost.html
您可以使用Boosting query在查询时实现这一点
摄取文档
查询(索引时间)
响应
有关更高级的操作,您可以检查Function Score Query
相关问题 更多 >
编程相关推荐