Skip to content

Commit

Permalink
Add doc about elasticsearch mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jan 11, 2023
1 parent 7ddb435 commit dd1dab2
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 21 deletions.
225 changes: 225 additions & 0 deletions packages/seal-elasticsearch-adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,228 @@ $engine = new Engine(
$schema,
);
```

## Schema Mapping

This shows how the [Seal Schema](../seal/README.md#schema) is mapped to Elasticsearch.

There is no diff between sortable and filterable fields so that cases are not specific listed.

| searchable | filterable / sortable | description |
|------------|-----------------------|-----------------------------------------------------------------------------|
| yes | no | Searchable but can not be used for filter or sorting |
| no | yes | Is not keep in mind for search score but can be used for filter and sorting |
| yes | yes | Is keep in mind for search score and can be used for filter and sorting |
| no | no | Just stored no index, analyzing required |

### IdentifierField

Field:

```php
new IdentifierField('id');
```

Mapping:

```json
{
"id": {
"type": "keyword",
"index": true,
"doc_values": true
}
}
```

Also the identifier is used as elasticsearch internal `_id` field.

### TextField

Field:

```php
new TextField('text_a', searchable: true, filterable: false, sortable: false), // default
new TextField('text_b', searchable: false, filterable: true, sortable: true),
```

Mapping:

```json
{
"text_a": {
"type": "text",
"index": true,
"doc_values": false
},
"text_b": {
"type": "text",
"index": true,
"doc_values": true,
"field": {
"raw": {
"type": "keyword",
"index": true,
"doc_values": true
}
}
}
}
```

### BooleanField

Field:

```php
new BooleanField('bool_a', searchable: true, filterable: false, sortable: false), // default
new BooleanField('bool_b', searchable: false, filterable: true, sortable: true),
```

Mapping:

```json
{
"bool_a": {
"type": "boolean",
"index": true,
"doc_values": false
},
"bool_b": {
"type": "boolean",
"index": true,
"doc_values": true
}
}
```

### DateTimeField

Field:

```php
new DateTimeField('date_a', searchable: true, filterable: false, sortable: false), // default
new DateTimeField('date_b', searchable: false, filterable: true, sortable: true),
```

Mapping:

```json
{
"date_a": {
"type": "date",
"index": true,
"doc_values": false
},
"date_b": {
"type": "date",
"index": true,
"doc_values": true
}
}
```

### IntegerField

Field:

```php
new IntegerField('int_a', searchable: true, filterable: false, sortable: false), // default
new IntegerField('int_b', searchable: false, filterable: true, sortable: true),
```

Mapping:

```json
{
"int_a": {
"type": "integer",
"index": true,
"doc_values": false
},
"int_b": {
"type": "integer",
"index": true,
"doc_values": true
}
}
```

### FloatField

Field:

```php
new FloatField('float_a', searchable: true, filterable: false, sortable: false), // default
new FloatField('float_b', searchable: false, filterable: true, sortable: true),
```

Mapping:

```json
{
"float_a": {
"type": "float",
"index": true,
"doc_values": false
},
"float_b": {
"type": "float",
"index": true,
"doc_values": true
}
}
```

### ObjectField

Field:

```php
new ObjectField('object', /* ... */);
```

Mapping:

```json
{
"object": {
"type": "object",
"properties": {
/* ... */
}
}
}
```

### TypedField

Field:

```php
new TypedField('typed', 'type', ['type_a' => /* ... */, 'type_b' => /* ... */]);
```

Mapping:

```json
{
"typed": {
"type": "object",
"properties": {
"type_a": {
"type": "object",
"properties": {
/* ... */
}
},
"type_b": {
"type": "object",
"properties": {
/* ... */
}
}
}
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public function testComplexElasticsearchMapping(): void
],
],
],
'published' => [
'type' => 'date',
],
'rating' => [
'type' => 'float',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public function testComplexOpensearchMapping(): void
],
],
],
'published' => [
'type' => 'date',
],
'rating' => [
'type' => 'float',
],
Expand Down
28 changes: 8 additions & 20 deletions packages/seal/Testing/TestingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Schranz\Search\SEAL\Schema\Index;
use Schranz\Search\SEAL\Schema\Schema;
use Schranz\Search\SEAL\Schema\Field;
use Schranz\Search\SEAL\Task\TaskInterface;

class TestingHelper
{
Expand Down Expand Up @@ -45,7 +44,8 @@ public static function createSchema(): Schema
'footer' => new Field\ObjectField('footer', [
'title' => new Field\TextField('title'),
]),
'created' => new Field\DateTimeField('created', filterable: true, sortable: true),
'created' => new Field\DateTimeField('created', searchable: false, filterable: true, sortable: true),
'published' => new Field\DateTimeField('published', filterable: true, sortable: true),
'commentsCount' => new Field\IntegerField('commentsCount', searchable: false, filterable: true, sortable: true),
'rating' => new Field\FloatField('rating', searchable: false, filterable: true, sortable: true),
'comments' => new Field\ObjectField('comments', [
Expand Down Expand Up @@ -125,7 +125,8 @@ public static function createComplexFixtures(): array
'footer' => [
'title' => 'New Footer',
],
'created' => '2022-01-24T12:00:00+01:00',
'created' => '1998-01-24T12:00:00+01:00',
'published' => '2022-01-24T12:00:00+01:00',
'commentsCount' => 2,
'rating' => 3.5,
'comments' => [
Expand Down Expand Up @@ -153,7 +154,8 @@ public static function createComplexFixtures(): array
'footer' => [
'title' => 'Other Footer',
],
'created' => '2022-12-26T12:00:00+01:00',
'created' => '1998-12-26T12:00:00+01:00',
'published' => '2022-12-26T12:00:00+01:00',
'commentsCount' => 0,
'rating' => 2.5,
'comments' => [],
Expand All @@ -167,7 +169,8 @@ public static function createComplexFixtures(): array
'footer' => [
'title' => 'Other Footer',
],
'created' => '2023-02-03T12:00:00+01:00',
'created' => '1999-02-03T12:00:00+01:00',
'published' => '2023-02-03T12:00:00+01:00',
'commentsCount' => 0,
'rating' => null,
'comments' => [],
Expand All @@ -180,21 +183,6 @@ public static function createComplexFixtures(): array
];
}

/**
* @param \Closure(TaskInterface[]: $tasks) $callback
*/
public static function waitForTasks(\Closure $callback): void
{
/** @var TaskInterface[] $tasks */
$tasks = [];

($callback)($tasks);

foreach ($tasks as $task) {
$task->wait();
}
}

/**
* @return array<array{
* id: string,
Expand Down
3 changes: 2 additions & 1 deletion packages/seal/Tests/Marshaller/MarshallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ private function getRawDocument(): array
'footer' => [
'title' => 'New Footer',
],
'created' => '2022-01-24T12:00:00+01:00',
'created' => '1998-01-24T12:00:00+01:00',
'published' => '2022-01-24T12:00:00+01:00',
'commentsCount' => 2,
'rating' => 3.5,
'comments' => [
Expand Down

0 comments on commit dd1dab2

Please sign in to comment.