Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
[fix] Limit of total fields [1000] in index [index] has been exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalik Shirokov committed Apr 28, 2020
1 parent 38da9e6 commit b6889cd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ public function putMapping(string $index, IndexMapping $mapping)
);
}

$propertiesCount = count($mapping->getProperties());
$propertiesCountLimit = $propertiesCount * 2 <= 1000 ? 1000 : $propertiesCount * 2;
$this->getElastic()->indices()->putSettings([
'index' => $index,
'body' => ['index' => ['mapping' => ['total_fields' => ['limit' => $propertiesCountLimit]]]]
]);

$response = $this->getElastic()->indices()->putMapping([
'index' => $index,
'body' => $mappingData
Expand Down
36 changes: 36 additions & 0 deletions tests/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,42 @@ public function testCanPutIndexMapping(array $stack = [])
return $stack;
}

/**
* @depends testCanPutIndexMapping
* @param array $stack
* @return array
*/
public function testCanPutIndexMappingWithManyProperties(array $stack = [])
{
/** @var Indexer $indexer */
$indexer = $stack['indexer'];

$mapping = new IndexMapping();
foreach (range(1, 2000) as $i) {
$mapping->setProperty("PROPERTY_$i", new PropertyMapping());
}

$this->assertCount(2000, $mapping->getProperties()->getArrayCopy());

for ($i = 0; $i < 2; $i++) {
$isSuccess = $indexer->putMapping('test_limit', $mapping);
$this->assertTrue($isSuccess);

$existMapping = $indexer->getMapping('test_limit');
$this->assertInstanceOf(IndexMapping::class, $existMapping);

/** @var PropertyMapping $propertyMap */
foreach ($mapping->getProperties()->getArrayCopy() as $property => $propertyMap) {
$this->assertEquals(
$propertyMap->getData()->getArrayCopy(),
$existMapping->getProperty($property)->getData()->getArrayCopy()
);
}
}

return $stack;
}

public function testCanPutIndexData()
{
$iBlock = CIBlock::GetList(null, ['=TYPE' => 'elastic_test', '=CODE' => 'PRODUCTS'])->Fetch();
Expand Down

0 comments on commit b6889cd

Please sign in to comment.