Skip to content

Commit

Permalink
add es7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
saimaz committed Feb 4, 2020
1 parent a27a4d9 commit 0a0d317
Show file tree
Hide file tree
Showing 29 changed files with 102 additions and 217 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ php:
- 7.3
env:
global:
- ES_VERSION=6.2.3 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
- ES_VERSION=7.5.2 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
matrix:
- SYMFONY="~3.4"
- SYMFONY="^4.1"
- SYMFONY="^4.4"
install:
- wget ${ES_DOWNLOAD_URL}
- tar -xzf elasticsearch-${ES_VERSION}.tar.gz
Expand Down
8 changes: 0 additions & 8 deletions Annotation/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ final class Index extends AbstractAnnotation

public $numberOfReplicas = 1;

/**
* We strongly recommend to not use this parameter in the index annotation. By default it will be set as `_doc`
* type name. Eventually it will be removed.
*
* @deprecated will be removed in v7 since there will be no more types in the indexes.
*/
public $typeName = '_doc';

/**
* You can select one of your indexes to be default. Useful for cli commands when you don't
* need to define an alias name. If default is not set the first index found will be set as default one.
Expand Down
1 change: 0 additions & 1 deletion DependencyInjection/Compiler/MappingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ private function handleDirectoryMapping(ContainerBuilder $container, string $dir
$indexMetadata,
$indexesOverride[$namespace]['hosts'] ?? $document->hosts,
$indexesOverride[$namespace]['default'] ?? $document->default,
$indexesOverride[$namespace]['type'] ?? $document->typeName
]
);

Expand Down
36 changes: 1 addition & 35 deletions Mapping/DocumentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ public function getIndexAnnotation(\ReflectionClass $class)
return $document;
}

/**
* @deprecated will be deleted in v7. Types are deleted from elasticsearch.
*/
public function getTypeName(\ReflectionClass $class): string
{
/** @var Index $document */
$document = $this->reader->getClassAnnotation($class, Index::class);

return $document->typeName ?? '_doc';
}

public function getIndexMetadata(\ReflectionClass $class): array
{
if ($class->isTrait()) {
Expand All @@ -102,34 +91,11 @@ public function getIndexMetadata(\ReflectionClass $class): array
return array_filter(array_map('array_filter', [
'settings' => $settings,
'mappings' => [
$this->getTypeName($class) => [
'properties' => array_filter($this->getClassMetadata($class))
]
'properties' => array_filter($this->getClassMetadata($class))
]
]));
}

public function getDocumentNamespace(string $indexAlias): ?string
{
if ($this->cache->contains(Configuration::ONGR_INDEXES)) {
$indexes = $this->cache->fetch(Configuration::ONGR_INDEXES);

if (isset($indexes[$indexAlias])) {
return $indexes[$indexAlias];
}
}

return null;
}

public function getParsedDocument(\ReflectionClass $class): Index
{
/** @var Index $document */
$document = $this->reader->getClassAnnotation($class, Index::class);

return $document;
}

private function getClassMetadata(\ReflectionClass $class): array
{
$mapping = [];
Expand Down
22 changes: 1 addition & 21 deletions Mapping/IndexSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,20 @@ class IndexSettings
private $hosts;
private $defaultIndex = false;



/**
* @deprecated will be removed in the v7
*/
private $type;

public function __construct(
string $namespace,
string $indexName,
string $alias,
array $indexMetadata = [],
array $hosts = [],
bool $defaultIndex = false,
$type = null
bool $defaultIndex = false
) {
$this->namespace = $namespace;
$this->indexName = $indexName;
$this->alias = $alias;
$this->indexMetadata = $indexMetadata;
$this->hosts = $hosts;
$this->defaultIndex = $defaultIndex;
$this->type = $type;
}

public function getNamespace()
Expand Down Expand Up @@ -109,15 +100,4 @@ public function setDefaultIndex(bool $defaultIndex): self
$this->defaultIndex = $defaultIndex;
return $this;
}

public function getType()
{
return $this->type;
}

public function setType($type): self
{
$this->type = $type;
return $this;
}
}
6 changes: 2 additions & 4 deletions Resources/doc/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ So here's a simple example how the data looks like:

[
{"count":2,"date":"2015-10-25T14:46:21+0200"},
{"_type":"content","_id":"15","_source":{"id":"15","title":"About","content":"Sample ONGR about page..","urls":[{"url":"about\/","key":""}]}},
{"_type":"content","_id":"37","_source":{"id":"37","title":"Home Page","content":"<div class=\"jumbotron\">\r\n <h1>Welcome to ONGR demo site!<\/h1>\r\n <p>Enterprise E-commerce Accelerator.<\/p><\/div>","urls":[{"url":"home-page\/","key":""}]}}
{"_id":"15","_source":{"id":"15","title":"About","content":"Sample ONGR about page..","urls":[{"url":"about\/","key":""}]}},
{"_id":"37","_source":{"id":"37","title":"Home Page","content":"<div class=\"jumbotron\">\r\n <h1>Welcome to ONGR demo site!<\/h1>\r\n <p>Enterprise E-commerce Accelerator.<\/p><\/div>","urls":[{"url":"home-page\/","key":""}]}}
]

```

Every line of file is `JSON` object. First line must specify `count`, how many lines are in the files except first and the file timestamp in `date`.

There is one document per line. There could be different types defined in a single file, basically with a single file you can import the whole index. There are 3 required keys:
* `_type` which specifies elasticsearch type name (not an ElasticsearchBundle class document)
* `_id` is optional, if not specified (provided `null`) elasticsearch will create a random id for that document.
* `_source`: document array encoded to json object, where all fields are equal to the elasticsearch type field names.

Expand All @@ -78,7 +77,6 @@ Exports data from Elasticsearch index in a json format.
|:-----------:|:----------------------------:|:--------------------------------------------------------------------------------------:|
| `--manager` | *Manager name. e.g.* `default` | Used to select manager to create index for. If not specified, default manager is used. |
| `--chunk` | *Chunk size, default 500* | Specifies the size of each chunk to be received from Elasticsearch. This can be changed for performance reasons.
| `--types` | *Elasticsearch index type names* | Selected types to export, if no specified will export all index.
| `--split` | *Lines number* | This option indicates how many lines can be in single exported file.

> Index export generates the same `JSON` format as specified in the import chapter.
Expand Down
4 changes: 2 additions & 2 deletions Result/AbstractResultsIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function __construct(
if (isset($rawData['hits']['hits'])) {
$this->documents = $rawData['hits']['hits'];
}
if (isset($rawData['hits']['total'])) {
$this->count = $rawData['hits']['total'];
if (isset($rawData['hits']['total']['value'])) {
$this->count = $rawData['hits']['total']['value'];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Service/ExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function exportIndex(
$counter = 0;
}

$doc = array_intersect_key($data, array_flip(['_id', '_type', '_source']));
$doc = array_intersect_key($data, array_flip(['_id', '_source']));
$writer->push($doc);
$progress->advance();
$counter++;
Expand Down
16 changes: 1 addition & 15 deletions Service/IndexService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ public function getNamespace(): string
return $this->namespace;
}

/**
* @deprecated will be removed in v7 since there will be no more types in the indexes.
*/
public function getTypeName(): string
{
return $this->indexSettings->getType();
}

public function getIndexSettings()
{
return $this->indexSettings;
Expand Down Expand Up @@ -189,7 +181,6 @@ public function find($id, $params = [])
{
$requestParams = [
'index' => $this->getIndexName(),
'type' => $this->getTypeName(),
'id' => $id,
];

Expand Down Expand Up @@ -319,7 +310,6 @@ public function getIndexDocumentCount(): int
{
$body = [
'index' => $this->getIndexName(),
'type' => $this->getTypeName(),
'body' => [],
];

Expand All @@ -332,7 +322,6 @@ public function remove($id, $routing = null)
{
$params = [
'index' => $this->getIndexName(),
'type' => $this->getTypeName(),
'id' => $id,
];

Expand All @@ -358,7 +347,6 @@ public function update($id, array $fields = [], $script = null, array $params =
[
'id' => $id,
'index' => $this->getIndexName(),
'type' => $this->getTypeName(),
'body' => $body,
],
$params
Expand All @@ -371,7 +359,6 @@ public function search(array $query, array $params = []): array
{
$requestParams = [
'index' => $this->getIndexName(),
'type' => $this->getTypeName(),
'body' => $query,
];

Expand All @@ -397,11 +384,10 @@ public function search(array $query, array $params = []): array
public function bulk(string $operation, array $data = [], $autoCommit = true): array
{
$bulkParams = [
'_type' => $this->getTypeName(),
'_id' => $data['_id'] ?? null,
];

unset($data['_index'], $data['_type'], $data['_id']);
unset($data['_index'], $data['_id']);

$this->eventDispatcher->dispatch(
Events::BULK,
Expand Down
3 changes: 1 addition & 2 deletions Service/Json/JsonReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ protected function readLine()
protected function configureResolver(OptionsResolver $resolver)
{
$resolver
->setRequired(['_id', '_type', '_source'])
->setRequired(['_id', '_source'])
->setDefaults(['_score' => null, 'fields' => []])
->addAllowedTypes('_id', ['integer', 'string'])
->addAllowedTypes('_type', 'string')
->addAllowedTypes('_source', 'array')
->addAllowedTypes('fields', 'array');
}
Expand Down
6 changes: 0 additions & 6 deletions Tests/Functional/Annotation/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@

class DocumentTest extends AbstractElasticsearchTestCase
{
public function testDocumentTypeName()
{
$index = $this->getIndex(DummyDocumentInTheEntityDirectory::class, false);
$this->assertEquals('_doc', $index->getTypeName());
}

public function testDocumentIndexName()
{
$index = $this->getIndex(DummyDocument::class, false);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Annotation/PropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testPropertyTypeName()
],
'type' => 'text',
],
$meta['mappings']['_doc']['properties']['title']
$meta['mappings']['properties']['title']
);
}
}
16 changes: 0 additions & 16 deletions Tests/Functional/Command/IndexExportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private function transformDataToResult(string $class): array
$id = $document['_id'];
unset($document['_id']);
$expectedResults[] = [
'_type' => $index->getTypeName(),
'_id' => $id,
'_source' => $document,
];
Expand Down Expand Up @@ -148,21 +147,6 @@ private function parseResult($filePath, $expectedCount)

$this->assertEquals($expectedCount, $metadata['count']);

usort(
$results,
function ($a, $b) {
if ($a['_type'] == $b['_type']) {
if ($a['_id'] == $b['_id']) {
return 0;
}

return $a['_id'] < $b['_id'] ? -1 : 1;
}

return $a['_type'] < $b['_type'] ? -1 : 1;
}
);

return $results;
}
}
Loading

0 comments on commit 0a0d317

Please sign in to comment.