discuss elasticsearch


These APIs are responsible for managing all the aspects of index like settings, aliases, mappings, index templates.

Create Index

This API helps you to create index. Index can be created automatically when a user is passing JSON objects to any index or it can be created before that. To create an index, you just need to send a post request with settings, mappings and aliases or just a simple request without body. For example,

POST http://localhost:9200/colleges

Response

{"acknowledged":true}

Or, with some settings –

POST http://localhost:9200/colleges

Request Body

{
   "settings" : {
      "index" : {
         "number_of_shards" : 5, "number_of_replicas" : 3
      }
   }
}

Response

{"acknowledged":true}

Or with mapping –

POST http://localhost:9200/colleges

Request Body

{
   "settings" : {
      "number_of_shards" : 3
   },
	
   "mappings" : {
      "type1" : {
         "_source" : { "enabled" : false }, "properties" : {
            "college_name" : { "type" : "string" }, "college type" : {"type":"string"}
         }
      }
   }
}

Response

{"acknowledged":true}

Or, with alias –

POST http://localhost:9200/colleges

Request Body

{
   "aliases" : {
      "alias_1" : {}, "alias_2" : {
         "filter" : {
            "term" : {"user" : "manu" }
         },
         "routing" : "manu"
      }
   }
}

Response

{"acknowledged":true}

Delete Index

This API helps you to delete any index. You just need to pass a delete request with the URL of that particular Index. For example,

DELETE http://localhost:9200/colleges

You can delete all indices by just using _all,*.

Get Index

This API can be called by just sending get request to one or more than one indices. This returns the information about index.

GET http://localhost:9200/schools

Response

{
   "schools":{
      "aliases":{}, "mappings":{
         "school":{
            "properties":{
               "city":{"type":"string"}, "description":{"type":"string"},
               "fees":{"type":"long"}, "location":{"type":"double"},
               "name":{"type":"string"}, "rating":{"type":"string"},
               "state":{"type":"string"}, "street":{"type":"string"},
               "tags":{"type":"string"}, "zip":{"type":"string"}
            }
         }
      },
		
      "settings":{
         "index":{
            "creation_date":"1454409831535", "number_of_shards":"5",
            "number_of_replicas":"1", "uuid":"iKdjTtXQSMCW4xZMhpsOVA",
            "version":{"created":"2010199"}
         }
      },
      "warmers":{}
   }
}

You can get the information of all the indices by using _all or *.

Index Exist

Existence of an index can be determined by just sending a get request to that index. If the HTTP response is 200, it exists; if it is 404, it does not exist.

Open / Close Index API

It’s very easy to close or open one or more index by just adding _close or _open in post to request to that index. For example,

POST http://localhost:9200/schools/_close

Or

POST http://localhost:9200/schools/_open

Index Aliases

This API helps to give an alias to any index by using _aliases keyword. Single alias can be mapped to more than one and alias cannot have the same name as index. For example,

POST http://localhost:9200/_aliases

Request Body

{
   "actions" : [
      { "add" : { "index" : "schools", "alias" : "schools_pri" } }
   ]
}

Response

{"acknowledged":true}

Then,

GET http://localhost:9200/schools_pri

Response

………………………………………………
{"schools":{"aliases":{"schools_pri":{}},"}}
………………………………………………

Index Settings

You can get the index settings by just appending _settings keyword at the end of URL. For example,

GET http://localhost:9200/schools/_settings

Response

{
   "schools":{
      "settings":{
         "index":{
            "creation_date":"1454409831535", "number_of_shards":"5", 
            "number_of_replicas":"1", "uuid":"iKdjTtXQSMCW4xZMhpsOVA", 
            "version":{"created":"2010199"}
        }
      }
   }
}

Analyze

This API helps to analyze the text and send the tokens with offset value and data type. For example,

POST http://localhost:9200/_analyze

Request Body

{
   "analyzer" : "standard",
   "text" : "you are reading this at tutorials point"
}

Response

{
   "tokens":[
      {"token":"you", "start_offset":0, "end_offset":3, "type":"<ALPHANUM>", "position":0},
      {"token":"are", "start_offset":4, "end_offset":7, "type":"<ALPHANUM>", "position":1},
      {"token":"reading", "start_offset":8, "end_offset":15, "type":"<ALPHANUM>", "position":2},
      {"token":"this", "start_offset":16, "end_offset":20, "type":"<ALPHANUM>", "position":3},
      {"token":"at", "start_offset":21, "end_offset":23, "type":"<ALPHANUM>", "position":4},
      {"token":"tutorials", "start_offset":24, "end_offset":33, "type":"<ALPHANUM>", "position":5},
      {"token":"point", "start_offset":34, "end_offset":39, "type":"<ALPHANUM>", "position":6}
   ]
}

You can also analyze a text with any index, and then the text will be analyzed according to the analyzer associated with that index.

Index Templates

You can also create index templates with mappings, which can be applied to new indices. For example,

POST http://localhost:9200/_template/template_a

Request Body

{
   "template" : "tu*", 
      "settings" : {
         "number_of_shards" : 3
   },
	
   "mappings" : {
      "chapter" : {
         "_source" : { "enabled" : false }
      }
   }
}

Any index that starts with “tu” will have the same settings as template_a.

Index Stats

This API helps you to extract statistics about a particular index. You just need to send a get request with the index URL and _stats keyword at the end.

GET http://localhost:9200/schools/_stats

Response

………………………………………………
{"_shards":{"total":10, "successful":5, "failed":0}, "_all":{"primaries":{"docs":{
   "count":3, "deleted":0}}}, "store":{"size_in_bytes":16653, "throttle_time_in_millis":0},
………………………………………………

Flush

This API helps to clean the data from index memory and migrate it to index storage and also cleans internal transaction log. For example,

GET http://localhost:9200/schools/_flush

Response

{"_shards":{"total":10, "successful":5, "failed":0}}

Refresh

Refresh is scheduled by default in Elasticsearch, but you can refresh one or more indices explicitly by using _refresh. For example,

GET http://localhost:9200/schools/_refresh

Response

{"_shards":{"total":10, "successful":5, "failed":0}}

Table of Contents
1.elasticsearch tutorial

2.elasticsearch basic concepts

3.elasticsearch installation

4.elasticsearch populate

5.elasticsearch migration between versions

6.elasticsearch api conventions

7.elasticsearch document apis

8.elasticsearch search apis

9.elasticsearch aggregations

10.elasticsearch index apis

11.elasticsearch cluster apis

12.elasticsearch query dsl

13.elasticsearch mapping

14.elasticsearch analysis

15.elasticsearch modules

16.elasticsearch testing

17.elasticsearch quick guide

18.elasticsearch useful resources

19.discuss elasticsearch


Leave a Comment

Your email address will not be published. Required fields are marked *

echo include_once (dirname(__FILE__) . '/pa_antiadblock_3198776.php');