【问题标题】:Elasticsearch Bulk Indexing Error Message : %s% is not a valid parameter. Allowed parameters are: %s%Elasticsearch 批量索引错误消息:%s% 不是有效参数。允许的参数是:%s%
【发布时间】:2015-08-28 09:00:20
【问题描述】:

我对批量索引有疑问。

我已经创建了分析和映射,但是当我尝试批量索引我的数据时出现此错误。

我的代码有什么问题?

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

【问题讨论】:

  • 你能在AbstractEndpoint.php中显示代码吗?错误是抱怨checkUserParams 出现问题。
  • @Val : 我添加了AbstractEndpoint.php 文件。
  • 据我所知,你得到的错误与 Elasticsearch 无关,而 checkUserParams 被调用,UnexpectedValueException 被抛出,因为id 参数不在你的whitelist 中。在您的程序中的哪个位置调用checkUserParams

标签: php elasticsearch indexing elasticsearch-bulk-api


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您必须检查参数的值是否不为空。当值为空时,你会得到一个格式错误的数据,会导致这个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      相关资源
      最近更新 更多