You are here

public function SearchApiElasticsearchBackend::getFieldMapping in Elasticsearch Connector 8

Helper function. Get the elasticsearch mapping for a field.

1 call to SearchApiElasticsearchBackend::getFieldMapping()
SearchApiElasticsearchBackend::fieldsUpdated in src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php
Overrides fieldsUpdated().

File

src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php, line 922
Contains the SearchApiElasticsearchBackend object.

Class

SearchApiElasticsearchBackend
Plugin annotation @SearchApiBackend( id = "elasticsearch", label = @Translation("Elasticsearch"), description = @Translation("Index items using an Elasticsearch server.") )

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

Code

public function getFieldMapping(FieldInterface $field) {
  try {
    $type = $field
      ->getType();
    switch ($type) {
      case 'text':
        return array(
          'type' => 'string',
          'boost' => $field['boost'],
        );
      case 'uri':
      case 'string':
      case 'token':
        return array(
          'type' => 'string',
          'index' => 'not_analyzed',
        );
      case 'integer':
      case 'duration':
        return array(
          'type' => 'integer',
        );
      case 'boolean':
        return array(
          'type' => 'boolean',
        );
      case 'decimal':
        return array(
          'type' => 'float',
        );
      case 'date':
        return array(
          'type' => 'date',
          'format' => 'date_time',
        );
      default:
        return NULL;
    }
  } catch (\Exception $e) {
    watchdog('Elasticsearch Backend', String::checkPlain($e
      ->getMessage()), array(), WATCHDOG_ERROR);
  }
}