暂存
This commit is contained in:
@@ -16,6 +16,7 @@ class OpenSearchChunkIndex
|
||||
$index = $this->indexName();
|
||||
|
||||
if ($client->indices()->exists(['index' => $index])) {
|
||||
$this->ensureProperties($client, $index);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,6 +65,7 @@ class OpenSearchChunkIndex
|
||||
'page_start' => ['type' => 'integer'],
|
||||
'page_end' => ['type' => 'integer'],
|
||||
'title' => $this->textWithKeyword(),
|
||||
'summary' => ['type' => 'text'],
|
||||
'source' => $this->textWithKeyword(),
|
||||
'author' => $this->textWithKeyword(),
|
||||
'year' => ['type' => 'integer'],
|
||||
@@ -93,6 +95,31 @@ class OpenSearchChunkIndex
|
||||
return $this->client ?? (new OpenSearchClientFactory())->make();
|
||||
}
|
||||
|
||||
private function ensureProperties(Client $client, string $index): void
|
||||
{
|
||||
$mapping = $client->indices()->getMapping(['index' => $index]);
|
||||
$existing = $mapping[$index]['mappings']['properties'] ?? [];
|
||||
$desired = $this->mapping()['mappings']['properties'] ?? [];
|
||||
$missing = [];
|
||||
|
||||
foreach ($desired as $field => $definition) {
|
||||
if (!array_key_exists($field, $existing)) {
|
||||
$missing[$field] = $definition;
|
||||
}
|
||||
}
|
||||
|
||||
if ($missing === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$client->indices()->putMapping([
|
||||
'index' => $index,
|
||||
'body' => [
|
||||
'properties' => $missing,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function indexName(): string
|
||||
{
|
||||
return config('opensearch.indices.chunks', 'proofdb_chunks');
|
||||
|
||||
Reference in New Issue
Block a user