include/SugarSearchEngine/Elastic/Elastica/Client.php
Client to connect the the elasticsearch server
- Author
- Nicolas Ruflin
- Category
- Xodoa
- Package
- Elastica
\Elastica_Client
Client to connect the the elasticsearch server
- Author
- Nicolas Ruflin
- Category
- Xodoa
Constants
Properties

array
$_config= 'array(
'host' => self::DEFAULT_HOST,
'port' => self::DEFAULT_PORT,
'transport' => self::DEFAULT_TRANSPORT,
'timeout' => self::TIMEOUT,
'headers' => array(),
'servers' => array(),
'roundRobin' => false,
'log' => false,
)'
Config with defaults
array(
'host' => self::DEFAULT_HOST,
'port' => self::DEFAULT_PORT,
'transport' => self::DEFAULT_TRANSPORT,
'timeout' => self::TIMEOUT,
'headers' => array(),
'servers' => array(),
'roundRobin' => false,
'log' => false,
)Details- Type
- array
Methods

__construct(
array $config
=
array()
)
:
voidCreates a new Elastica client
| Name | Type | Description |
|---|---|---|
| $config | array | OPTIONAL Additional config options |

addDocuments(
array $docs
)
:
\Elastica_ResponseUses _bulk to send documents to the server
Array of Elastica_Document as input. Index and type has to be set inside the document, because for bulk settings documents, documents can belong to any type and index
| Name | Type | Description |
|---|---|---|
| $docs | array | Array of Elastica_Document |
| Type | Description |
|---|---|
| \Elastica_Response | Response object |
| Exception | Description |
|---|---|
| \Elastica_Exception_Invalid | If docs is empty |

addHeader(
string $header, string $headerValue
)
:
voidAdds a HTTP Header
| Name | Type | Description |
|---|---|---|
| $header | string | The HTTP Header |
| $headerValue | string | The HTTP Header Value |
| Exception | Description |
|---|---|
| \Elastica_Exception_Invalid | If $header or $headerValue is not a string |

bulk(
array $params
)
:
\Elastica_ResponseBulk operation
Every entry in the params array has to exactly on array of the bulk operation. An example param array would be:
array( array('index' => array('_index' => 'test', '_type' => 'user', '_id' => '1')), array('user' => array('name' => 'hans')), array('delete' => array('_index' => 'test', '_type' => 'user', '_id' => '2')) );
| Name | Type | Description |
|---|---|---|
| $params | array | Parameter array |
| Type | Description |
|---|---|
| \Elastica_Response | Reponse object |

deleteDocuments(
array $docs
)
:
voidBulk deletes documents (not implemented yet)
| Name | Type | Description |
|---|---|---|
| $docs | array | Docs |
| Exception | Description |
|---|---|
| \Elastica_Exception |

deleteIds(
array $ids, string | \Elastica_Index $index, string | \Elastica_Type $type
)
:
\Elastica_ResponseDeletes documents with the given ids, index, type from the index
| Name | Type | Description |
|---|---|---|
| $ids | array | Document ids |
| $index | string | \Elastica_Index | Index name |
| $type | string | \Elastica_Type | Type of documents |
| Type | Description |
|---|---|
| \Elastica_Response | Response object |
| Exception | Description |
|---|---|
| \Elastica_Exception | If ids is empty |

getCluster(
)
:
\Elastica_ClusterReturns the current cluster
| Type | Description |
|---|---|
| \Elastica_Cluster | Cluster object |

getConfig(
string $key
=
''
)
:
array | stringReturns a specific config key or the whole config array if not set
| Name | Type | Description |
|---|---|---|
| $key | string | Config key |
| Type | Description |
|---|---|
| array | string | Config value |

getIndex(
string $name
)
:
\Elastica_IndexReturns the index for the given connection
| Name | Type | Description |
|---|---|---|
| $name | string | Index name to create connection to |
| Type | Description |
|---|---|
| \Elastica_Index | Index for the given name |

getStatus(
)
:
\Elastica_StatusReturns the status object for all indices
| Type | Description |
|---|---|
| \Elastica_Status | Status object |

getTransport(
)
:
stringReturns transport type to user
| Type | Description |
|---|---|
| string | Transport type |

optimizeAll(
array $args
=
array()
)
:
\Elastica_ResponseOptimizes all search indices
| Name | Type | Description |
|---|---|---|
| $args | array | OPTIONAL Optional arguments |
| Type | Description |
|---|---|
| \Elastica_Response | Response object |

removeHeader(
string $header
)
:
voidRemove a HTTP Header
| Name | Type | Description |
|---|---|---|
| $header | string | The HTTP Header to remove |
| Exception | Description |
|---|---|
| \Elastica_Exception_Invalid | IF $header is not a string |

request(
string $path, string $method, array $data
=
array()
)
:
\Elastica_ResponseMakes calls to the elasticsearch server based on this index
It's possible to make any REST query directly over this method
| Name | Type | Description |
|---|---|---|
| $path | string | Path to call |
| $method | string | Rest method to use (GET, POST, DELETE, PUT) |
| $data | array | OPTIONAL Arguments as array |
| Type | Description |
|---|---|
| \Elastica_Response | Response object |

setConfig(
array $config
)
:
voidSets specific config values (updates and keeps default values)
| Name | Type | Description |
|---|---|---|
| $config | array | Params |

setConfigValue(
string $key, mixed $value
)
:
\Elastica_ClientSets / overwrites a specific config value
| Name | Type | Description |
|---|---|---|
| $key | string | Key to set |
| $value | mixed | Value |
| Type | Description |
|---|---|
| \Elastica_Client | Client object |