get invalid json response with scroll ?

get invalid json response with scroll ?

matt.crawfoordmatt.crawfoord Posts: 31Questions: 13Answers: 0

i want to load search results to jQuery datatable,i have set the scroll for query and set "deferRender": true, in my table , but why get the invalid json response !

if( !empty($requestData['_scroll_id']) ) 
 {

   $qryurl = '<ip:url>/index*/_search?search_type=scan&scroll=1m&size=20'  
   $data = array(   ....... 

 }

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $qryurl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch,CURLOPT_HEADER,false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$return = curl_exec($ch) or die(curl_error());
$array_return = json_decode($return,true);
curl_close($ch);
    $hittotal = $array_return['hits']['total'];
$scroll_id = $array_return['_scroll_id'];
    $source = $array_return['hits']['hits'];
$sourcecount=count($array_return['hits']['hits']);
    $sourceary = array();
    for($i=0;$i<$sourcecount;$i++)
    {
    $msgary = $array_return['hits']['hits'][$i]['_source'];

       array_push($sourceary,$msgary);
         }

$results = array(
    "draw"  => $scroll_id,
"iTotalRecords" => $hittotal,
     "iTotalDisplayRecords" => $hittotal,
"aaData"=>$sourceary
        );

echo json_encode($results);

javascript ,

$(document).ready(function() {
 var table = $('#example').DataTable( {
    "ajax": {
        url : "elk_response.php",
       type: 'POST',
       data: {
       from: "<?php echo $from; ?>",
       to: "<?php echo $to; ?>",
       device:"<?php echo $device; ?>",
       keyword:"<?php echo $keyword; ?>",
       index: "<?php echo $index; ?>"

    },
    },
    "columns": [
        {
            "className":      'details-control',
            "orderable":      false,
            "data":           null,
            "defaultContent": ''
        },
        { "data": "datetime" },
        { "data": "message" }
    ],
    "order": [[1, 'asc']],
    "scrollY":        400,
    "scrollCollapse": true,
    "deferRender":    true,
    "paging":         false,
    "scroller":       true
} );

Any help would be great. Thanks

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.