elasticsearch问题与查询

问题描述:

嗨我打算在我的项目中使用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 
      } 
     ] 
     } 
    ] 
} 

我怎样才能得到结果的标题,正文标签及评析领域,其中日期为马克斯(如果两个日期相同)和comments.priority领域,其中前是征求意见,其中日期分钟是最大值?这是posibble?谢谢你的帮助

+0

请提供示例输出。 – Richa

+0

是的,这是可能的 –

{ 
"fields": ["comments.name", "title", "body", "tags"], 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "nested": { 
      "path": "comments", 
      "query": { 
       "bool": { 
       "must": [ 
        { "match": { "comments.name": "john" }}, 
        { "match": { "comments.age": 28  }} 
       ] 
     }}}} 
     ] 
}}} 



{"took":5,"timed_out":false,"_shards": 
{"total":1,"successful":1,"failed":0},"hits": 
{"total":1,"max_score":2.4114075,"hits": 
[{"_index":"test","_type":"produkt","_id":"1","_score":2.4114075,"fields": 
{"comments.name":["Mary Brown","John Smith"],"title":["Investment 
secrets"],"body":["What they don't tell you ..."],"tags": 
["shares","equities"]}}]}} 

怎么只返回姓名约翰史密斯?

确定的解决方案是 “inner_hits”:{}

但接下来的问题是如何得到的意见,其中日期是最大,在SQL EQ

SELECT * FROM表,其中comments.date =(选择最大(comments.date)