Tôi đang tích hợp elaticsearch với Laravel theo cách rất đơn giản. Vì vậy, đây là lớp tôi đã phát triển cho sự tích hợp này. Xin lỗi lộn xộn có 5. Giới hạn 000 ký tự, vì vậy tôi phải xóa nhận xét
// all variables was declared
public function __construct[]
{
$this->params = array[];
$this->params['hosts'] = $this->host;
$this->params['guzzleOptions']['command.request_options']['connect_timeout'] = 240; // Standard value 2.0
$this->params['guzzleOptions']['command.request_options']['timeout'] = 240; // Standard value 2.0
$this->client = \Elasticsearch\ClientBuilder::create[$this->params]
->setHosts[[$this->host]]
->build[];
}
public function index[]
{
$this->destroy[];
$this->create[];
$this->map[];
$this->indexFile['File1.pdf'];
$this->indexFile['File2.pdf'];
$this->indexFile['File3.pdf'];
$this->indexFile['File4.pdf'];
}
public function create[]
{
$this->params = [
'index' => $this->index
// ,'client' => [
// 'timeout' => 0, // ten second timeout
// 'connect_timeout' => 0
// ],
];
$this->client->indices[]->create[$this->params];
}
public function destroy[]
{
$this->params = [
'index' => $this->index
];
$this->client->indices[]->delete[$this->params];
}
public function map[]
{
$this->params = [
'index' => $this->index,
'type' => $this->type,
'body' => [
$this->type => [
'properties' => [
'file' => [
'type' => 'attachment',
'fields' => [
'content' => [
'type' => 'string',
'term_vector' => 'with_positions_offsets',
'store' => true
]
]
]
]
]
]
];
$this->client->indices[]->putMapping[$this->params];
}
public function indexFile[$file = null]
{
if [ empty[$file] ]{
return false;
}
$file = storage_path['app/' . $this->file_path . $file];
if [ is_file[$file] ] {
$this->params = [
'index' => $this->index,
'type' => $this->type,
'timeout' => '5m',
// Curl timeoute Option 4
// 'client' => [
// 'timeout' => 0, // ten second timeout
// 'connect_timeout' => 0
// ],
'body' => [
'file' => [
'_content_type' => 'application/pdf',
'_name' => $file,
'_language' => 'en',
'_indexed_chars' => -1,
'_content' => base64_encode[file_get_contents[$file]]
]
]
];
$this->client->index[$this->params];
echo 'File "' . $file . '" was indexed.
';
} else {
return false;
}
}
}
Lỗi tương tự khi sử dụng lập chỉ mục hàng loạt
Có ai phải đối mặt với vấn đề này?
Cảm ơn trước
Ok, vì bạn đang sử dụng 2. x, các tham số thời gian chờ chính xác là những tham số bạn đã nhận xét. Vì vậy, bạn có thể tiếp tục và quay trở lại những. e. g
$this->params = [
'index' => $this->index,
'type' => $this->type,
'client' => [
'timeout' => 240,
'connect_timeout' => 240
],
'body' => [
'file' => [
'_content_type' => 'application/pdf',
'_name' => $file,
'_language' => 'en',
'_indexed_chars' => -1,
'_content' => base64_encode[file_get_contents[$file]]
]
]
];
$this->client->index[$this->params];
Thành thật mà nói, tôi không chắc về Apache. Đã nhiều năm kể từ khi tôi sử dụng Apache. Nó rất tốt có thể là thời gian chờ đó. nếu Apache quyết định giết tiến trình vì nó đã chạy quá lâu, thì điều đó trông rất giống với việc PHP giết nó vì lý do tương tự. Có lẽ có một cách bạn có thể ghi đè lên nó trong tệp .htaccess
?
Có phải thời gian chờ này chỉ xảy ra khi lập chỉ mục các tệp PDF không? . g. nếu bạn chạy qua tất cả mã của mình, nhưng bỏ qua phần lập chỉ mục PDF, nó có hoạt động không?
Tôi đã kiểm tra dòng nguồn lỗi [] và nó đang gán một hàm ẩn danh cho một giá trị trong một mảng. Điều đó khiến tôi tin rằng đây thực sự là một sự chấm dứt mạnh mẽ, vì đó là một nơi kỳ lạ cho một ngoại lệ