簡體   English   中英

在ElasticSearch中聚合嵌套對象

[英]Aggregate nested objects in ElasticSearch

假設我們有此文檔:

{
    "Article" : [
      {
        "id" : 12
        "title" : "An article title",
        "categories" : [1,3,5,7],
        "tag" : ["elasticsearch", "symfony",'Obtao'],
        "author" : [
            {
                "firstname" : "Francois",
                "surname": "francoisg",
                "id" : 18
            },
            {
                "firstname" : "Gregory",
                "surname" : "gregquat"
                "id" : "2"
            }
        ]
      }
    },
    {
        "id" : 13
        "title" : "A second article title",
        "categories" : [1,7],
        "tag" : ["elasticsearch", "symfony",'Obtao'],
        "author" : [
            {
                "firstname" : "Gregory",
                "surname" : "gregquat",
                "id" : "2"
            }
        ]
      }
}

如何按ID查找所有唯一作者? 什么是正確的查詢? 我需要返回所有唯一作者(“ author.id”)

感謝幫助。

首先,您應該為字段author設置nested類型的映射。 第二,正如@Taras_Kohut所述,在重新索引整個數據之后,您可以執行以下操作:

{
  "size": 0,
  "aggregations": {
    "records": {
      "nested": {
        "path": "author"
      },
      "aggregations": {
        "ids": {
          "terms": {
            "field": "author.id"
          }
        }
      }
    }
  }
}

請參閱嵌套聚合

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM