php解析Elasticsearch的返回值

来源:互联网 发布:php mongodb remove 编辑:程序博客网 时间:2024/06/09 20:51

下面是通过Es搜索查找出来的值$data

{    "took": 2,    "timed_out": false,    "_shards": {        "total": 5,        "successful": 5,        "failed": 0    },    "hits": {        "total": 495,        "max_score": null,        "hits": [        {            "_index": "post",            "_type": "full",            "_id": "869480",            "_score": null,            "_source": {                "hit": 201,                "create_time": "1476942098",                "reply": 4,                "content": "有续期是个好服务,为了无缝对接,需要提前取消也",                "title": "人人 未经同意自动续期产品的流氓行为",                "tid": "869480",                "type": 1,                "username": "breathxue",                "lastpost": "1476953784",                "uid": "540553"            },            "highlight": {                "title": [                "<em class="c_color">人人</em><em class="c_color"></em> 未经同意自动续期产品的流氓行为"                ]           },            "sort": [                "1476953784"            ]        }]   } }

解析的代码:

public function EsData($data){    $datas=json_decode($data);    $total = $data->hits->total;    $data=$datas->hits->hits;    $res=array();    foreach($data as $item){        $res['index'] = $item->_index;        $res['id'] = $item->_id;        $res['content'] = $item->_source->content;    }    return $res;}
0 0
原创粉丝点击