2015-06-12 14 views
0

我有關於批量索引的問題。Elasticsearch批量索引錯誤消息:%s%不是有效的參數。允許的參數是:%s%

我已經創建了分析和映射,但是當我嘗試批量索引我的數據時出現此錯誤。

我的代碼有什麼問題?

Elasticsearch_error

object(Elasticsearch\Common\Exceptions\UnexpectedValueException)[321] 
    protected 'message' => string '"id" is not a valid parameter. Allowed parameters are: "consistency", "refresh", "replication", "type", "client", "custom"' (length=122) 
    private 'string' (Exception) => string '' (length=0) 
    protected 'code' => int 0 
    protected 'file' => string 'D:\xampp\htdocs\lisento\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Endpoints\AbstractEndpoint.php' (length=107) 
    protected 'line' => int 245 
    private 'trace' (Exception) => 
    array (size=21) 
     0 => 
     array (size=6) 
      'file' => string 'D:\xampp\htdocs\lisento\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Endpoints\AbstractEndpoint.php' (length=107) 
      'line' => int 97 
      'function' => string 'checkUserParams' (length=15) 
      'class' => string 'Elasticsearch\Endpoints\AbstractEndpoint' (length=40) 
      'type' => string '->' (length=2) 
      'args' => 
      array (size=1) 
       0 => 
       array (size=1) 
        'id' => string '1234567890' (length=10) 

AbstractEndpoint.php

private function checkUserParams($params) 
{ 
    if (isset($params) !== true) { 
     return; //no params, just return. 
    } 

    $whitelist = array_merge($this->getParamWhitelist(), array('client', 'custom')); 

    foreach ($params as $key => $value) { 
     if (array_search($key, $whitelist) === false) { 
      throw new UnexpectedValueException(sprintf(
       '"%s" is not a valid parameter. Allowed parameters are: "%s"', 
       $key, 
       implode('", "', $whitelist) 
      )); 
     } 
    } 
} 

My_mapping

[ 
    "mappings" => [ 
     "twitter" => [ 
       "properties" => [ 
        "tweet_id" => [ "type" => "long" ], 
        "tweet_text" => [ 
         "type" => "string", 
         "fields" => [ 
          "raw" => [ "type" => "string", "index" => "no" ], 
          "text" => [ "type" => "string", "analyzer" => "tweet_text_autocomp_analyzer" ], 
          "std" => [ "type" => "string", "analyzer" => "tweet_text_std_analyzer" ] 
         ], 
        ], 
        "tweet_date" => ["type" => "date","format" => "Y-M-d H:m:s" ], 
        "favorited_count" => [ "type" => "integer" ], 
        "retweet_count" => [ "type" => "integer" ], 
        "place" => [ "type" => "string" ], 
        "url" => [ "type" => "string" ], 
        "hashtags" => [ 
         "type" => "nested", 
         "fields" => [ 
          "hashtag" => [ "type" => "string" ] 
         ], 
        ], 
        "campaign_id" => [ "type" => "long" ], 
        "user_id" => [ "type" => "long" ], 
        "screen_name" => [ "type" => "string" ] 
       ] 
      ] 
     ] 
] 

My_data

{ 
     "user_id": 117093939, 
     "screen_name": "", 
     "campaign_id": "1234567890", 
     "tweet_id": 609287367120150000, 
     "tweet_text": "Oberyn's scattered skull #GameOfThronesFood", 
     "tweet_date": "2015-06-12 16:13:22", 
     "favorited_count": 0, 
     "retweet_count": 0, 
     "url": "" 
    }, 
    { 
     "user_id": 491504312, 
     "screen_name": "", 
     "campaign_id": "1234567890", 
     "tweet_id": 609287361751610000, 
     "tweet_text": "RT @alex_backes: Buffalo Wildlings #GameOfThronesFood @midnight", 
     "tweet_date": "2015-06-12 16:13:21", 
     "favorited_count": 0, 
     "retweet_count": 43, 
     "url": "" 
    }, 
    { 
     "user_id": 745355136, 
     "screen_name": "", 
     "campaign_id": "1234567890", 
     "tweet_id": 609287345951610000, 
     "tweet_text": "RT @CMPunk: Jon snow cones! @midnight #GameOfThronesFood", 
     "tweet_date": "2015-06-12 16:13:17", 
     "favorited_count": 0, 
     "retweet_count": 203, 
     "url": "" 
    } 
} 

My_bulk_code

for ($j = 0; $j <= $i; $j++) { 
    $params ['body'][] = array(
     'index' => array(
      'index' => $appconfig['ES_INDEX'], 
      'type' => $index["type"], 
      '_id' => $j, 
      'body' => $index["docs"] 
     ), 
    ); 

    // Every 1000 documents stop and send the bulk request 
    if ($j % 1000) { 
     $responses = $client->bulk($params); 

     // erase the old bulk request 
     $params = array(); 

     // unset the bulk response when you are done to save memory 
     unset($responses); 
    } 
}   
+0

你能在'AbstractEndpoint.php'中顯示代碼嗎?錯誤是抱怨'checkUserParams'出錯了。 – Val

+0

@Val:我添加了'AbstractEndpoint.php'文件。 – blaxroze

+0

從我看到的,你得到的錯誤與Elasticsearch無關,當調用'checkUserParams'時,由於'id'參數不在'whitelist'中,所以拋出'UnexpectedValueException'。在你的程序中的哪一點是'checkUserParams'叫? – Val

回答

0

您必須檢查param的值是否爲空。當該值爲空時,您將得到一個格式錯誤的數據,這將導致此錯誤。

相關問題