1

对于 Discovery REST api,参数/参数“return”控制返回哪些字段。

因此,如果我将这些参数传递给 API

  {
              "query": named_sector,
              "count": "10",
              "filter": filter_dates,
              "aggregation" : "term(docSentiment.type,count:3)"
    }
    my_query = discovery.query(my_disc_environment_id, my_disc_collection_id, qopts)
    print(json.dumps(my_query, indent=2))

我得到以下信息:

{
    "matching_results": 14779,
    "aggregations": [
        {
            "type": "term",
            "field": "docSentiment.type",
            "count": 3,
            "results": [
                {
                    "key": "positive",
                    "matching_results": 4212
                },
                {
                    "key": "negative",
                    "matching_results": 3259
                },
                {
                    "key": "neutral",
                    "matching_results": 152
                }
            ]
        }
    ],
    "results": [
        {
            "id": "6389715fe7e7f711e0bc09d4f1236639",
            "score": 1.3689895,
            "yyyymm": "201704",
            "url": "https://seekingalpha.com/article/4060446-valuation-dashboard-consumer-discretionary-update",
            "enrichedTitle": null,
            "host": "seekingalpha.com",
            "text": "Valuation Dashboard: Consumer Discretionary - Update\n\nSummary\n\nValuation metrics in Consumer Discretionary.\n\nEvolution since last month.\n\nA list of stocks loo ....

以及数千行。如何将输出限制到聚合部分?这是我更好地处理返回的 JSON 结构的问题吗?

谢谢

4

1 回答 1

0

如果将 count 参数更改为 0,则返回的 JSON 将仅包含聚合。

此外,如果您使用 Discovery Web 工具,您可以在“返回的结果数(计数)”字段中输入 0。

可以在此处找到更多详细信息和示例:https ://www.ibm.com/watson/developercloud/doc/discovery/using.html#building-aggregations

于 2017-04-28T19:22:17.630 回答