对于Discovery REST api,参数/参数"返回"控制返回哪些字段。
所以,如果我将这些参数传递给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结构的问题吗?
感谢
答案 0 :(得分:0)
如果将count参数更改为0,则返回的JSON将仅包含聚合。
此外,如果您正在使用Discovery网络工具,则可以输入0作为"要返回的结果数(计数)"字段。
更多细节和示例可在此处找到:https://www.ibm.com/watson/developercloud/doc/discovery/using.html#building-aggregations