我使用elasticsearch构建了一个自动完成搜索,因此我需要查询3个索引posts
,comments
,authors
。我有以下查询:Elasticsearch - 对多索引查询进行排序
{
"query":{
"query_string":{
"query":"something"
}
}
}
电话:
curl -X GET 'http://localhost:9200/posts,comments,authors/_search?pretty' -d '{
"query": {
"query_string": {
"query": "something"
}
}
}'
我需要通过特定的索引字段对结果进行排序,例如:
帖子指数有一个字段名为comments_count
评论votes_count
和作者posts_count
。当比较帖子时,则应按comments_count
排序,当评论时votes_count
,当时作者为posts_count
。
可以这样做吗?我不想将索引合并为一个索引,因为它们索引完全不同的文档。
“如果我排序所有索引中不存在的字段,文档将不会返回”。这是可控的。参见http://www.elasticsearch.org/guide/reference/api/search/sort/。在你的情况下,你应该使用'{“missing”:“_last”}' –