我想知道如何在elasticsearch的aggs查询中投影所有字段。假设我有这个数据集:

{
sent_id: 1
doc_id: 5
text: "test1"
year: "2015"
}
{
sent_id: 2
doc_id: 5
text: "test2"
year: "2015"
}

我想根据我的doc_id对所有具有特定条件的句子进行分组。我想要这样的结果:
doc_id:5
{
    {sent_id:1, year:2015, text: "test1"},
    {sent_id:2, year:2015, text: "test2"},
    etc
},
doc_id: xx
{
    {sent_id:xx, year:2015, text: "xx"}
}

下面的内容或多或少给了我我想要的东西,除了它不投影所有其他字段。
"query": {
    "query_string": {
      "fields": ["text"],
      "query" : "affordable energy"}}
  ,"size": 0
  ,"aggs":{
    "doc_id":{
            "terms": {
        "field": "doc_id"
        ,"size": 0
      },
       "aggs": {
            "sents_info": {
                "terms": {
                    "field": "sent_id",
                    "size": 0
                }
            }
        }
    }
  }

最佳答案

  "aggs": {
    "doc_id": {
      "terms": {
        "field": "doc_id",
        "size": 0
      },
      "aggs": {
        "sents_info": {
          "terms": {
            "field": "sent_id",
            "size": 0
          },
          "aggs": {
            "top10": {
              "top_hits": {
                "size": 10
              }
            }
          }
        }
      }
    }
  }

关于elasticsearch - 在Elasticsearch中投影聚合中的所有字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38696407/

10-14 17:29
查看更多