たとえば、私は状態別に集計したいが、以下のデータは配列型ではない文字列tyepを返す。 配列を返すElasticsearch用語集を書くにはどうしたらいいですか?私のコードのurlibをpythonで配列を返す方法 - elasticsearchの呼び出し結果を解析しますか?
一部:
import urllib2 as urllib
import json
query = {
"size":0,
"aggs":{
"states":{
"terms":{
"field":"states.raw",
"size":8
}
}
}
}
query = json.dumps(query)
headers = {'Content-type': 'application/json'}
req = urllib2.Request(url, query , headers)
out = urllib2.urlopen(req)
rs = out.read()
print type(rs)
リターン:私はRS [ '集計'] [ '状態'] [ 'バケツ'] [0によって戻りデータを取得しよう
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": []
},
"aggregations": {
"states": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "New York",
"doc_count": 200
},
{
"key": "California",
"doc_count": 10
},
{
"key": "New Jersey",
"doc_count": 10
},
{
"key": "North Carolina",
"doc_count": 1802
},
{
"key": "North Dakota",
"doc_count": 125
}
]
}
}
}
] [「キー」] が、エラーMSGを取得
"TypeError: string indices must be integers, not str"
私は戻りデータを作成する方法、戻り値のデータ型が文字列で見つかっがあります配列?