如何通过elasticsearch索引获取字段中的所有disctinct对象?

时间:2018-04-26 05:50:40

标签: elasticsearch elasticsearch-5

我试图从整个索引中的字段中获取所有不同的对象。

到目前为止我尝试的是:

POST http://es5server:9200/indexname/_search
Content-Type: application/json

{
  "size": "1",
  "aggs": {
    "tags": {
      "terms": {
        "field": "tags"
      }
    }
  }
}

目前这为我返回以下内容(我将大小设置为1以包含示例文档):

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 2,
    "successful": 2,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 1.0,
    "hits": [
      {
        "_index": "indexname",
        "_type": "news",
        "_id": "51",
        "_score": 1.0,
        "_source": {
          "localized": {
            "de": {
              "title": null,
              "shorttext": null,
              "text": null
            },
            "en": {
              "title": "test new title",
              "shorttext": "hello my name is mayur and this is testnews text",
              "text": null
            }
          },
          "type": "object",
          "key": "testnews",
          "path": "\/",
          "tags": {
            "38": {
              "name": "I AM",
              "parent": "0"
            },
            "45": {
              "name": "ffddd",
              "parent": "43"
            },
            "43": {
              "name": "kkjjttdd",
              "parent": "0"
            }
          }
        }
      }
    ]
  },
  "aggregations": {
    "tags": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": []
    }
  }
}

存储桶是空的,这是因为标签字段包含对象而不包含文本吗?

如何让ES返回所有文档的标签字段中的所有不同对象?

1 个答案:

答案 0 :(得分:0)

看起来您需要为您提供嵌套对象解决方案。看到此问题已解答here