简体   繁体   English

在Elasticsearch中按其他数据排序。 可能吗?

[英]Ordering by additional data in Elasticsearch. Is it possible?

I want search all results in list -- 我想搜索列表中的所有结果-

# [ [num, pk], [1, 34], [2, 3147] ...]
# num = [0, 1, 2, ... 7]
pks = [34, 3147,..., 1264]

I want search where related__in=pks , but like this. 我想搜索related__in=pks ,但是像这样。 First .filter(related=pk[0]) , then .filter(related=pk[1]) ... And concatenate results to single query. 首先是.filter(related=pk[0]) ,然后是.filter(related=pk[1]) ...并将结果串联到单个查询中。

SO: 所以:

Can I add some filed/data to searchqueryset to sort by it later? 我可以添加一些字段/数据到searchqueryset以便以后进行排序吗?

Or maybe concatenate many searchquerysets to one? 还是将许多searchqueryset连接为一个?

What you are describing is a Haystack MultiValueField that allow for search engines to query ManyToMany relations like you are hinting at in your answer. 您所描述的是一个Haystack MultiValueField ,它允许搜索引擎查询您所提示的ManyToMany关系。

This is demonstrated in the documentation like so : 在文档中对此进行了演示,如下所示

class NoteIndex(SearchIndex, indexes.Indexable):
    text = CharField(document=True, use_template=True)
    author = CharField(model_attr='user')
    categories = MultiValueField()

For details on how to efficiently query this field, see this related question . 有关如何有效查询此字段的详细信息, 请参阅此相关问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM