dongyouzhui1969 2015-06-23 10:28
浏览 590
已采纳

Elasticsearch实现按字段和方向排序

I've been reading the documentation and other example posts since yesterday to work out how to add sort by field and the direction to my current query array here but so far no luck. I've seen examples like {"sort": {"_score": "desc"}, "query": { .... but couldn't quiet get my head around it to modify my array since this is the very first time I'm dealing with ES.

All I need is: I want to be able to sort by price or stock in asc or desc order.

Everytime I try to update my array to implement sorting, I get {"error":{"code":0,"message":"Invalid option sort"}} error.

NOTE: The query array is being passed to Pagerfanta to get results.

    $paginator = $this->productFinder->findPaginated($myArray)
        ->setMaxPerPage($limit)
        ->setCurrentPage($page);
  • 写回答

2条回答

  • dpl22899 2015-07-11 08:53
    关注

    For the specific field and direction:

    {
       "sort": {
          "price": "asc"
       }
       ... rest of the code
    }
    

    For no particular sorting (this is set by default):

    {
       "sort": {
          "_score": "desc"
       }
       ... rest of the code
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件