2016-08-16 85 views
0

我有弹性搜索文件嵌套场有2场:排序嵌套文档在搜索弹性

blog = Nested(
    properties={ 
     'id': Integer(), 
     'rating': Integer() 
    } 
) 

的ES文件具有博客的列表:blog1,blog2等

我希望所有blob.id = x的文档并在与该blob相对应的评级字段上排序。 用没有排名脚本的弹性搜索查询来执行此操作是否可行?请指教。

回答

1

这样的事情应该做你需要什么:

{ 
    "query": { 
    "nested": { 
     "path": "blog", 
     "query": { 
     "term": { 
      "blog.id": 123 
     } 
     } 
    } 
    }, 
    "sort": [ 
    { 
     "blog.rating": { 
     "order": "asc", 
     "nested_path": "blog", 
     "nested_filter": { 
      "term": { 
      "blog.id": 123 
      } 
     } 
     } 
    } 
    ] 
}