簡體   English   中英

Elasticsearch批量索引錯誤消息:%s%不是有效參數。 允許的參數為:%s%

[英]Elasticsearch Bulk Indexing Error Message : %s% is not a valid parameter. Allowed parameters are: %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)
            ));
        }
    }
}

我的地圖

[
    "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" ]
                ]
            ]
        ]
]

我的數據

{
      "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);
    }
}           

這就是答案。 https://github.com/elastic/elasticsearch-php/issues/247,它工作正常。

您必須檢查參數的值不為空。 當該值為空時,您將獲得格式錯誤的數據,這將導致此錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM