ElasticSearch:无法解析搜索源。预期的字段名称,但有[START_OBJECT] -php

时间:2018-08-07 12:30:37

标签: php elasticsearch

错误

{"error":
    {
        "root_cause":[ 
        {"type":"parse_exception","reason":"failed to parse search source. expected field name but got [START_OBJECT]"}
    ],
        "type":"search_phase_execution_exception","reason":"all shards failed",
        "phase":"query","grouped":true,
        "failed_shards":[{"shard":0,
        "index":"revenue_itemwise",
        "node":"aoTq2dI7SxyMlCgVHeWIHg",
        "reason":{"type":"parse_exception","reason":"failed to parse search source. expected field name but got [START_OBJECT]"}
    }
    ]
    },"status":400}

我正在尝试从2个索引中获取匹配数据,然后推送到另一个索引。 1.选择第一个索引中的数据 2.将数据传递到第二个索引 3.获取匹配的记录 4.创建新索引并推送数据

<?php
use Elasticsearch\ClientBuilder;
require_once 'vendor/autoload.php';
$config = json_decode ( file_get_contents ( 'conf.json' ), true );
$host= implode(':', $config ["es_source1"]);
$esSourceClient1 = ClientBuilder::create ()
        ->setHosts (array($host))
        ->build ();
$indexEdd = "ltz_edds";
$indexEddType = "edd";
$indexBillItems = "revenue_itemwise";
$indexBillItemsType = "revenue";
$indexValue=0;
$params = [
        "scroll"=> "30s", 
        "size"  => 10000,
        "index" => $indexEdd,
        'type'  =>  $indexEddType,
        'body'  => [
                'query' => [
                        'exists' => [
                                'field' => 'effective_edd'
                        ],

                ]
        ]

];
$response = $esSourceClient1->search ( $params );
while ( array_key_exists('hits',$response ['hits'] )  && count ( $response ['hits']['hits'] ) > 0) {
    $scroll_id = $response ['_scroll_id'];
    $response = $esSourceClient1->scroll ( [
            "scroll_id" => $scroll_id,
            "scroll" => "30s",
            "body"=>$scroll_id
    ] )
    ;
    $eddData = $response ['hits']['hits'];
    foreach ($eddData as $key => $value) {
        $patientParams = [
                'index' => $indexBillItems,
                'type' => $indexBillItemsType,
                'body' => [
                        'query' => [
                                'exists' => [
                                        'field' => 'mpi'
                                ],
                                'match' => [
                                        'mpi' => $value ['_source'] ['mpi']
                                ]
                        ]
                ]
        ];
        $patientResponse = $esSourceClient1->search ($patientParams);
    }
    $patientData = $patientResponse['hits']['hits'];
    foreach ($eddData as $eddKey => $eddValue){
        foreach ($patientData as $patientDatakey => $patientDataValue){
            if($eddValue['_source']['mpi']==$patientDataValue['_source']['mpi']){
                $result[$indexValue]['last_consult_by']=$eddValue['_source']['last_consult_by'];
                $result[$indexValue]['mpi']=$eddValue['_source']['mpi'];
                $result[$indexValue]['bill_id']=$patientDataValue['_source']['bill_id'];
                $result[$indexValue]['bill_date']=date('Y-m-d', strtotime($patientDataValue['_source']['bill_date']));
                $result[$indexValue]['site']=$eddValue['_source']['site'];
                $result[$indexValue]['effective_edd']=date('Y-m-d', strtotime($eddValue['_source']['effective_edd']));
                $result[$indexValue]['is_converted']=$eddValue['_source']['is_converted'];
                $result[$indexValue]['admitting_physician']=$patientDataValue['_source']['admitting_physician'];
                $dateEdd = date_create($eddValue['_source']['effective_edd']);
                $datePatient = date_create($patientDataValue['_source']['bill_date']);
                $dateDiff = date_diff($dateEdd, $datePatient);
                $dateDiffindays = $dateDiff -> d;
                $result[$indexValue]['days']=$dateDiffindays;
                switch ($result[$indexValue]['days']){
                    case ($result[$indexValue]['days']>0 && $result[$indexValue]['days']<=90):
                        $result[$indexValue]['trim']='{"trim3" : 1}';
                        break;
                    case ($result[$indexValue]['days']>90 && $result[$indexValue]['days']<=180):
                        $result[$indexValue]['trim']='{"trim2" : 1}';
                        break;
                    case ($result[$indexValue]['days']>180 && $result[$indexValue]['days']<=270):
                        $result[$indexValue]['trim']='{"trim1" : 1}';
                        break;
                }
                $indexValue++;
            }else{
                $result=array();
            }

        }
    }
    foreach ($result as $resKey => $resValue){

        $params = [
                'index' => $timester,
                'type'  => $timester,
                'body'  =>  $resValue
        ];

        $res = $esSourceClient1->index($params);

    }
}

这是我用于建立新索引的代码。请提出我想念的地方?

ES版本= 2.0并使用https://packagist.org/packages/elasticsearch/elasticsearch

0 个答案:

没有答案