You are here

public static function MappingFactory::mappingFromField in Elasticsearch Connector 8.2

Same name and namespace in other branches
  1. 8.7 src/ElasticSearch/Parameters/Factory/MappingFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\MappingFactory::mappingFromField()
  2. 8.5 src/ElasticSearch/Parameters/Factory/MappingFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\MappingFactory::mappingFromField()
  3. 8.6 src/ElasticSearch/Parameters/Factory/MappingFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\MappingFactory::mappingFromField()

Helper function. Get the elasticsearch mapping for a field.

Parameters

FieldInterface $field:

Return value

array|null

1 call to MappingFactory::mappingFromField()
IndexFactory::mapping in src/ElasticSearch/Parameters/Factory/IndexFactory.php
Build parameters required to create an index mapping TODO: We need also: $params['index'] - (Required) ['type'] - The name of the document type ['timeout'] - (time) Explicit operation timeout

File

src/ElasticSearch/Parameters/Factory/MappingFactory.php, line 20

Class

MappingFactory
Class MappingFactory.

Namespace

Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory

Code

public static function mappingFromField(FieldInterface $field) {
  try {
    $type = $field
      ->getType();
    switch ($type) {
      case 'text':
        return [
          'type' => 'string',
          'boost' => $field
            ->getBoost(),
          'analyzer' => 'snowball',
        ];
      case 'uri':
      case 'string':
      case 'token':
        return [
          'type' => 'string',
          'index' => 'not_analyzed',
        ];
      case 'integer':
      case 'duration':
        return [
          'type' => 'integer',
        ];
      case 'boolean':
        return [
          'type' => 'boolean',
        ];
      case 'decimal':
        return [
          'type' => 'float',
        ];
      case 'date':
        return [
          'type' => 'date',
          'format' => 'epoch_second',
        ];
      case 'attachment':
        return [
          'type' => 'attachment',
        ];
    }
  } catch (ElasticsearchException $e) {
    watchdog_exception('Elasticsearch Backend', $e);
  }
  return NULL;
}