我對ElasticSearch(版本2.3.3)非常新,這是我對數據的以下格式。ElasticSearch在整個數據中出現的總數不同
{
"title": "Doc 1 title",
"year": "14",
"month": "06",
"sentences": [
{
"id": 1,
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"class": "Introduction",
"synth": "intr"
},
{
"id": 2,
"text": "Donec molestie pulvinar odio, ultricies dictum mi porttitor sit amet.",
"class": "Introduction",
"synth": "abstr"
},
{
"id": 3,
"text": "Aliquam id tristique diam. Suspendisse convallis convallis est ut condimentum.",
"class": "Main_Content",
"synth": "body"
},
{
"id": 4,
"text": "Nunc ornare eros at pretium faucibus. Praesent congue cursus aliquet.",
"class": "Main_Content",
"synth": "body"
},
{
"id": 5,
"text": "Integer pellentesque quam ut nulla dignissim hendrerit.",
"class": "Future_Work",
"synth": "ftr"
},
{
"id": 6,
"text": "Pellentesque faucibus vehicula diam.",
"class": "Bibliography",
"synth": "bio"
}
]
}
而且,諸如doc1,doc2,...,doc700的多個文檔。
我想要生成這樣一個查詢,我得到了整個文檔批量按年排序的每個不同「類」的出現總次數。
所以,結果將類似於以下內容。
{
"year" : "14",
"count" : [
{ "Introduction" : 1357 },
{ "Main_Content" : 1021 },
{ "Future_Work" : 490 },
{ "Bibliography" : 241 }
],
"year" : "15",
"count" : [
{ "Introduction" : 972 } ,
{ "Main_Content" : 712 },
{ "Future_Work" : 335 },
{ "Bibliography" : 81 }
]
}
是否可以實現我張貼的內容?或者,對於每個「班級」來說,這樣做會更容易嗎?
非常感謝。
我已經嘗試了像你所建議的映射,但是當運行查詢時,我得到{ 「type」:「aggregation_execution_exception」, 「reason」:「[嵌套]嵌套路徑[句子]不是嵌套的」 } – Mayhem
你能驗證映射是否爲索引正確創建? –
是的,當我運行-XGET/index/_mapping/type時它會得到映射,但我不得不說我提出的問題數據不是整個數據。我試圖映射對查詢很重要的特定部分,其餘部分(我忽略)與查詢無關,並且不包含任何要搜索的字段並且計數爲 – Mayhem