- PHP Client: other versions:
- Overview
- Quickstart
- Installation
- Configuration
- Inline Host Configuration
- Extended Host Configuration
- Authorization and Encryption
- Set retries
- Enabling the Logger
- Configure the HTTP Handler
- Setting the Connection Pool
- Setting the Connection Selector
- Setting the Serializer
- Setting a custom ConnectionFactory
- Set the Endpoint closure
- Building the client from a configuration hash
- Per-request configuration
- Future Mode
- Dealing with JSON Arrays and Objects in PHP
- Index Management Operations
- Indexing Documents
- Getting Documents
- Updating Documents
- Deleting documents
- Search Operations
- Namespaces
- Security
- Connection Pool
- Selectors
- Serializers
- PHP Version Requirement
- Breaking changes from 5.x
- Community DSLs
- Community Integrations
- Reference - Endpoints
- Elasticsearch\Client
- Elasticsearch\ClientBuilder
- Elasticsearch\Namespaces\CatNamespace
- Elasticsearch\Namespaces\ClusterNamespace
- Elasticsearch\Namespaces\IndicesNamespace
- Elasticsearch\Namespaces\IngestNamespace
- Elasticsearch\Namespaces\NodesNamespace
- Elasticsearch\Namespaces\RemoteNamespace
- Elasticsearch\Namespaces\SnapshotNamespace
- Elasticsearch\Namespaces\TasksNamespace
SmartSerializer
editSmartSerializer
editSerialize()
editThe SmartSerializer
inspects the data to be encoded. If the request body
is provided as a string, it is passed directly to Elasticsearch as a string.
This allows users to provide raw JSON, or raw strings for certain endpoints that
dont have structure (such as the Analyze endpoint).
If the data is an array, it is converted to json. If the data provided was an
empty array, the serializer manually converts the JSON from an empty array ([]
)
to an empty object ({}
) so that it is valid JSON for Elasticsearch request
bodies.
Deserialize()
editWhen decoding the response body, the SmartSerializer
introspects the
content_type
headers to determine the appropriate encoding. If the data is
encoded as JSON, it is decoded into an array using json_decode
. Otherwise,
it is returned as a string.
This functionality is required to cooperate with endpoints such as the Cat
endpoints, which return tabular text instead of JSON.
Selecting the SmartSerializer
editThe SmartSerializer is selected by default, but if you wish to manually configure it for explicitness, you can
do so by using the setSerializer()
method on the ClientBuilder object:
$client = ClientBuilder::create() ->setSerializer('\Elasticsearch\Serializers\SmartSerializer'); ->build();
Note that the serializer is configured by specifying a namespace path to the serializer.