查询

时间:2016-02-12 17:21:38

标签: elasticsearch

您好我计划在我的项目中使用elasticsearch,但我是初学者。我的文档看起来像这样

{
   "title":"Investment secrets",
   "body":"What they don't tell you ...",
   "tags":[
      "shares",
      "equities"
   ],
   "comments":[
      {
         "name":"Mary Brown",
         "comment":"Lies, lies, lies",
         "age":42,
         "stars":1,
         "date":"2014-10-16",
         "priority":[
            {
               "prior":1,
               "some fields":1
            },
            {
               "prior":3,
               "some fields":3
            }
         ]
      },
      {
         "name":"John Smith",
         "comment":"You're making it up!",
         "age":28,
         "stars":2,
         "date":"2014-10-16",
         "priority":[
            {
               "prior":2,
               "some fields":2
            }
         ]
      }
   ]
}

我如何获得结果作为标题,正文标记和coments字段,其中日期是最大值(如果两个日期相同)和comments.priority字段,其中先前是min为评论,其中日期是最大值?它的位置?谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

private void timeout(RoutingContext ctx) {
    long tid = ctx.vertx().setTimer(5000, t -> {
        ctx.response().putHeader("location","/logout").setStatusCode(302).end();
    });
    ctx.addBodyEndHandler(v -> ctx.vertx().cancelTimer(tid));
}

如何仅返回John Smith的名字?

ok解决方案是“inner_hits”:{}

但下一个问题是如何获取日期为最大值的注释,sql中的e.q

从表中选择*,其中comments.date =(从表中选择max(comments.date))