diff --git a/includes/SearchApiElasticsearchAbstractService.inc b/includes/SearchApiElasticsearchAbstractService.inc
index 3823e04..1381ba1 100644
--- a/includes/SearchApiElasticsearchAbstractService.inc
+++ b/includes/SearchApiElasticsearchAbstractService.inc
@@ -114,6 +114,29 @@ abstract class SearchApiElasticsearchAbstractService extends SearchApiAbstractSe
           '#parents' => array('options', 'form', $c, 'port'),
         );
 
+        //Elasticsearch basic authentication.
+        $form['daemon_settings']['fieldset'][$c]['headers'] = array(
+          '#type' => 'fieldset',
+          '#tree' => TRUE,
+          '#title' => t('HTTP Basic Authentication'),
+          '#description' => t('If your Elasticsearch server is protected by basic HTTP authentication, enter the login data here.'),
+        );
+
+        //Elasticsearch basic authentication username.
+        $form['daemon_settings']['fieldset'][$c]['headers']['http_user'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Username'),
+          '#default_value' => (!empty($options[$c]['headers']) && !empty($options[$c]['headers']['http_user'])) ? $options[$c]['headers']['http_user'] : '',
+          '#parents' => array('options', 'form', $c, 'headers', 'http_user'),
+        );
+
+        //Elasticsearch basic password.
+        $form['daemon_settings']['fieldset'][$c]['headers']['http_pass'] = array(
+          '#type' => 'password',
+          '#title' => t('Password'),
+          '#parents' => array('options', 'form', $c, 'headers', 'http_pass'),
+        );
+
         // Elasticsearch daemon path.
         $form['daemon_settings']['fieldset'][$c]['path'] = array(
           '#type' => 'textfield',
@@ -257,6 +280,7 @@ abstract class SearchApiElasticsearchAbstractService extends SearchApiAbstractSe
       }
     }
 
+    $options = $this->getOptions();
     foreach ($values as $i => $setting) {
       if ($i != 'facet_limit') {
         // Daemon IP address.
@@ -271,6 +295,25 @@ abstract class SearchApiElasticsearchAbstractService extends SearchApiAbstractSe
 
         $values[$i]['path'] = $this->setPath($values[$i]['path']);
       }
+
+      // Put http_user and http_password in correct form.
+      if (!empty($setting['headers']['http_user'])) {
+        // If username matches the old value and password is empty, then use the old Authentication.
+        if (empty($setting['headers']['http_pass'])) {
+          if ($setting['headers']['http_user'] == $options[$i]['headers']['http_user']) {
+            $values[$i]['headers']['Authentication'] = $options[$i]['headers']['Authentication'];
+          }
+          // If username does not match and password is empty, then give a validation error.
+          else {
+            form_set_error('http_pass', t('If you are changing the username, you need to supply the password.'));
+            return;
+          }
+        }
+        else {
+          $values[$i]['headers']['Authentication'] = 'Basic ' . base64_encode($setting['headers']['http_user'] . ':' . $setting['headers']['http_pass']);
+        }
+      }
+      unset($values[$i]['headers']['http_pass']);
     }
   }
 
diff --git a/service.inc b/service.inc
index 5317d4d..e964fad 100644
--- a/service.inc
+++ b/service.inc
@@ -114,6 +114,29 @@ class SearchApiElasticsearchService extends SearchApiAbstractService {
           '#parents' => array('options', 'form', $c, 'port'),
         );
 
+        //Elasticsearch basic authentication.
+        $form['daemon_settings']['fieldset'][$c]['headers'] = array(
+          '#type' => 'fieldset',
+          '#tree' => TRUE,
+          '#title' => t('HTTP Basic Authentication'),
+          '#description' => t('If your Elasticsearch server is protected by basic HTTP authentication, enter the login data here.'),
+        );
+
+        //Elasticsearch basic authentication username.
+        $form['daemon_settings']['fieldset'][$c]['headers']['http_user'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Username'),
+          '#default_value' => (!empty($options[$c]['headers']) && !empty($options[$c]['headers']['http_user'])) ? $options[$c]['headers']['http_user'] : '',
+          '#parents' => array('options', 'form', $c, 'headers', 'http_user'),
+        );
+
+        //Elasticsearch basic password.
+        $form['daemon_settings']['fieldset'][$c]['headers']['http_pass'] = array(
+          '#type' => 'password',
+          '#title' => t('Password'),
+          '#parents' => array('options', 'form', $c, 'headers', 'http_pass'),
+        );
+
         // Elasticsearch daemon path.
         $form['daemon_settings']['fieldset'][$c]['path'] = array(
           '#type' => 'textfield',
@@ -258,6 +281,7 @@ class SearchApiElasticsearchService extends SearchApiAbstractService {
       }
     }
 
+    $options = $this->getOptions();
     foreach ($values as $i => $setting) {
       if ($i != 'facet_limit') {
         // Daemon IP address.
@@ -272,6 +296,25 @@ class SearchApiElasticsearchService extends SearchApiAbstractService {
 
         $values[$i]['path'] = $this->setPath($values[$i]['path']);
       }
+
+      // Put http_user and http_password in correct form.
+      if (!empty($setting['headers']['http_user'])) {
+        // If username matches the old value and password is empty, then use the old Authentication.
+        if (empty($setting['headers']['http_pass'])) {
+          if ($setting['headers']['http_user'] == $options[$i]['headers']['http_user']) {
+            $values[$i]['headers']['Authentication'] = $options[$i]['headers']['Authentication'];
+          }
+          // If username does not match and password is empty, then give a validation error.
+          else {
+            form_set_error('http_pass', t('If you are changing the username, you need to supply the password.'));
+            return;
+          }
+        }
+        else {
+          $values[$i]['headers']['Authentication'] = 'Basic ' . base64_encode($setting['headers']['http_user'] . ':' . $setting['headers']['http_pass']);
+        }
+      }
+      unset($values[$i]['headers']['http_pass']);
     }
   }
 
