elasticsearch-php namespaces

Source: Internet
Author: User
Tags vars

Name space

The client has a lot of namespaces and can often burst out of the functionality he manages. namespaces correspond to the endpoints of various elasticsearch management. The following is a list of the completed namespaces:

name Space function
Indices () Index-centric statistics and information
Nodes () Node-centric statistics and information
Cluster () Cluster-centric statistics and information
Snapshot () How to snapshot/restore your clusters and indicators
Cat () Access to the Cat API (which is typically used for standalone access from the command line)


Some methods can be used under different namespaces, giving you the same information, but grouped into different contexts. If you want to see how these namespaces work, let's look at the output of the _stats:

  1. $client = new Elasticsearch\client ();
  2. Index Stats
  3. Corresponds to Curl-xget localhost:9200/_stats
  4. $response = $client->indices ()->stats ();
  5. Node Stats
  6. Corresponds to Curl-xget localhost:9200/_nodes/stats
  7. $response = $client->nodes ()->stats ();
  8. Cluster Stats
  9. Corresponds to Curl-xget localhost:9200/_cluster/stats
  10. $response = $client->cluster ()->stats ();


As you can see, the same stats () call takes place in three different namespaces. Sometimes methods require parameters. These parameters work just like the methods in other libraries.

For example, we can request statistics for a specific index or multiple index information.

  1. $client = new Elasticsearch\client ();
  2. Corresponds to Curl-xget localhost:9200/my_index/_stats
  3. $params [' index '] = ' My_index ';
  4. $response = $client->indices ()->stats ($params);
  5. Corresponds to Curl-xget localhost:9200/my_index1,my_index2/_stats
  6. $params [' index '] = Array (' my_index1 ', ' my_index2 ');
  7. $response = $client->indices ()->stats ($params);


Another example is how to add an alias to an existing index.

  1. $params [' body '] = Array (
  2. ' actions ' = = Array (
  3. Array (
  4. ' add ' = = Array (
  5. ' index ' = ' myindex ',
  6. ' Alias ' = ' myalias '
  7. )
  8. )
  9. )
  10. );
  11. $client->indices ()->updatealiases ($params);


Note how stats calls and Updatealias accept a variety of parameters, each of which is based on the needs of a particular API. The stats API requires only an index name, but Updatealias requires a body action.

elasticsearch-php namespaces

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.