【发布时间】:2017-12-02 05:01:39
【问题描述】:
我在使用Elasticsearch 和Enron 电子邮件数据集做一些实验时很开心。我做了一个查询以获得对我的实际问题不重要的东西。我总共获得了 4 次点击,我想将此数字打印为:
The total number of hits is: 4
我的问题是:如何获得点击总数?
这是我的查询:
s = Search(using=client, index="enron_test").query('range', date={'gte': query_date_1, 'lte': query_date_2, "format": "dd/MM/yyyy||dd/MM/yyyy"})
这是从Sense获取的查询结果:
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
...
【问题讨论】:
-
s["hits"]["total"] -
如果我写下
print(["hits"]["total"]),它将无法返回TypeError: list indices must be integers, not str。如果我用s写下print(s["hits"]["total"]),它会返回<elasticsearch_dsl.search.Search object at 0x7f87f6698d50>
标签: python json elasticsearch