2017-09-09 194 views
1

我看到嵌套字段和聚合的幾個帖子,但他們都沒有回答我的問題。所以,請原諒,如果這是一個重複的問題,任何幫助將不勝感激。ElasticSearch:嵌套字段和聚合

我們已經建立了講座的指標,聽課具備以下素質:

  • 講座既可以親自(活的)或預錄(在線)
  • 每堂課能有多個章節
  • 這些章節中的每一章都可以被不同的講師所覆蓋(例如:量子物理學的第1章可以由五位不同的講師所覆蓋,其中三位可能在場,另外兩位可能在線)
  • 在線講座每次總是有一個條目每章講師每質量

大致結構如下:

{ 
    "topics": [ 
    { 
     "id": "TOP1", 
     "chapters": [ 
     { 
      "chapterId": 12345, 
      "availability": [ 
      { 
       "type": "LIVE", 
       "lecturer": "Dr. Abraham Fisher", 
       "lectureChapterId": "861731", 
       "availableFrom": "2017-09-11 13:00:00", 
       "expiresAt": "2017-09-11 15:00:00", 
       "lecturerIds": [ 
       "MON121", 
       "MEL122" 
       ] 
      }, 
      { 
       "type": "LIVE", 
       "lecturer": "Dr. Bob Fisher", 
       "lectureChapterId": "181751", 
       "availableFrom": "2017-09-11 20:00:00", 
       "expiresAt": "2017-09-11 22:00:00", 
       "lecturerIds": [ 
       "MON122", 
       "MEL123" 
       ] 
      }, 
      { 
       "type": "LIVE", 
       "lecturer": "Dr. Bob Fisher", 
       "lectureChapterId": "181751", 
       "availableFrom": "2017-09-17 20:00:00", 
       "expiresAt": "2017-09-17 22:00:00", 
       "lecturerIds": [ 
       "MON122", 
       "MEL123" 
       ] 
      }, 
      { 
       "type": "LIVE", 
       "lecturer": "Dr. Abraham Fisher", 
       "lectureChapterId": "861731", 
       "availableFrom": "2017-09-17 13:00:00", 
       "expiresAt": "2017-09-17 15:00:00", 
       "lecturerIds": [ 
       "MON121", 
       "MEL122" 
       ] 
      }, 
      { 
       "type": "ONLINE", 
       "quality" : "HD", 
       "price" : 19.99, 
       "lecturer": "Dr. Catherine Fisher", 
       "lectureChapterId": "9127312", 
       "availableFrom": "2017-01-17 00:00:00", 
       "expiresAt": "2017-12-31 23:59:59", 
       "lecturerIds": [ 
       "MON120", 
       "MEL120" 
       ] 
      }, 
      { 
       "type": "ONLINE", 
       "quality" : "SD", 
       "price" : 10.99, 
       "lecturer": "Dr. Catherine Fisher", 
       "lectureChapterId": "9127312", 
       "availableFrom": "2017-01-17 00:00:00", 
       "expiresAt": "2017-12-31 23:59:59", 
       "lecturerIds": [ 
       "MON120", 
       "MEL120" 
       ] 
      } 
      ] 
     } 
     ] 
    } 
    ] 
} 

現在如果要求是隻返回細節按章分組第一個可用的講座,講師現場授課,並返回所有在線講座(連同演講主題的其他元數據),那麼最好的方法是什麼?在上面的例子中,Abraham Fisher博士和Bob Fisher博士9月11日的講座應歸還。

我嘗試使用inner_hits,但顯然,它不允許聚合(我得到以下錯誤)。

"[nested] query does not support [aggs]" 

P.S:聚集需要處於一章水平而不是在演講主題(根)的水平。

回答