- 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
Create an index (advanced example)
editCreate an index (advanced example)
editThis is a more complicated example of creating an index, showing how to define analyzers, tokenizers, filters and index settings. Although essentially the same as the previous example, the more complicated example can be helpful for "real world" usage of the client, since this particular syntax is easy to mess up.
$params = [ 'index' => 'reuters', 'body' => [ 'settings' => [ 'number_of_shards' => 1, 'number_of_replicas' => 0, 'analysis' => [ 'filter' => [ 'shingle' => [ 'type' => 'shingle' ] ], 'char_filter' => [ 'pre_negs' => [ 'type' => 'pattern_replace', 'pattern' => '(\\w+)\\s+((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\b', 'replacement' => '~$1 $2' ], 'post_negs' => [ 'type' => 'pattern_replace', 'pattern' => '\\b((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\s+(\\w+)', 'replacement' => '$1 ~$2' ] ], 'analyzer' => [ 'reuters' => [ 'type' => 'custom', 'tokenizer' => 'standard', 'filter' => ['lowercase', 'stop', 'kstem'] ] ] ] ], 'mappings' => [ '_default_' => [ 'properties' => [ 'title' => [ 'type' => 'keyword', 'analyzer' => 'reuters', 'term_vector' => 'yes', 'copy_to' => 'combined' ], 'body' => [ 'type' => 'keyword', 'analyzer' => 'reuters', 'term_vector' => 'yes', 'copy_to' => 'combined' ], 'combined' => [ 'type' => 'keyword', 'analyzer' => 'reuters', 'term_vector' => 'yes' ], 'topics' => [ 'type' => 'keyword', 'index' => 'not_analyzed' ], 'places' => [ 'type' => 'keyword', 'index' => 'not_analyzed' ] ] ], 'my_type' => [ 'properties' => [ 'my_field' => [ 'type' => 'keyword' ] ] ] ] ] ]; $client->indices()->create($params);
The top level |
|
|
|
|
|
The |
|
The |