簡體   English   中英

Elasticsearch:如何使用映射為數千個文件建立索引?

[英]Elasticsearch: How do I index thousands of files using mapping?

我正在嘗試建立一個搜索引擎。 我將Php與elasticsearch一起使用。 手動執行base64編碼並為文件夾中的每個文件建立索引將是不可能的。 文件將大部分為Word或PDF格式。 我為最近的嘗試添加了代碼,但是沒有用。

<?php
    $dir_path="yellow";
    require 'vendor/autoload.php';
    $client= Elasticsearch\ClientBuilder::create()->build();
    if(is_dir($dir_path))
    {
        $files=opendir($dir_path);
        if($files)
        {
            while(($file_name= readdir($files))!== FALSE)
            {
                if($file_name!=="."&$file_name!=="..")
                {
        $params= [
        'index'=>'try',
        'type'=>'mytype',
        'body'=>[   
        'my_attachment' =>[
          "cv" => base64_encode(file_get_contents("$dir_path/$file_name"))  ]   ]
        ];

    $response= $client->index($params);
    echo $response;
                }
            }
        }
    }
?>

此代碼返回的是“通知:數組到字符串轉換的錯誤”錯誤,而不是生成確認。

嘗試更換

'body'=>[   
        'my_attachment' =>[
          "cv" => base64_encode(file_get_contents("$dir_path/$file_name"))  ]   ]

'body' => [
    'my_attachment' => 
     base64_encode(file_get_contents("$dir_path/$file_name"))
]

暫無
暫無

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

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