...

Search Engine - Elastic Search

Back to Course

Lesson Description


Lession - #135 ES Index APIs


Elasticsearch Index APIs

Elasticsearch gives Index API that deals with every one of the parts of a list, like record layout, planning, nom de plumes, and settings, and so forth. In Elasticsearch, Index API plays out the activity at the file level. It is liable for overseeing different records, list settings, record layouts, planning, document configuration, and monikers. At the point when a solicitation is made for a record with explicit planning, this API assists with adding or update the JSON archive in that particular file. It permits to perform number of procedure on lists, for example, - make, erase, investigate, revive, flush, and some more.

Create Index

This API is utilized to make a list. A file can be made by sending a PUT demand without body or with appropriate planning, setting, and assumed name. A list is made naturally at whatever point a client passes the JSON objects to any file. For example

POST http://localhost/9200/book/  
{ }  

By executing this query, we will get below response-

{  
    "acknowledge": true,  
    "shard_acknowledge": true,   
    "index": "book"  
}     

Get Index

Get API is utilized to give data about a specific record you need. It brings the data of file. This API is called simply by sending a GET demand alongside list name, which returns all the data about that specific file. It returns metadata with Get demand. Take a gander at the model beneath For example

GET http://localhost/9200/book/  
{ } 

By executing this query, we will get below response-

{  
    "took": 2084,  
    "timed_out": false,  
       "_shards": {  
          "total": 1,  
          "successful": 1,  
          "skipped": 0,  
          "failed": 0  
      },  
      "hits": {  
        "total": {  
            "value": 1,  
            "relation": "eq"  
        },  
        "max_score": 1,  
        "hits": [  
        {  
            "_index": "book",  
            "_type": "_doc",  
            "_id": "dkqwVnMB1ug6i0GdSAsj",  
            "_score": 1,  
            "_source": {  
                "setting": {  
                      "index": {  
                "number_of_shards": 4,  
                "number_of_replicas": 3  
                }  
            },  
            "mapping": {  
                 "type1": {  
                "_source": {  
                   "enabled": false  
                },  
                "properties": {  
                      "book_name": {  
                    "type":"string"  
                        },  
                      "author_name": {  
                    "type":"string"  
                        },  
                      "publish_date": {  
                    "type":"date"  
                        },  
                      "price": {  
                    "type":"float"  
                        },  
                      "publisher": {  
                    "type":"string"  
                        }  
                  }  
                    }  
             }  
               }  
        }  
         ]  
         }  
}  

Delete Index

The erase API is answerable for erasing any file present in elasticsearch. Whenever you really want to eliminate any record, pass the erase API alongside list name. You can likewise erase all files present in elasticsearch by passing _all or * immediately. For example

DELETE http://localhost/9200/book/  
{ }  

By executing this query, we will get below response-

{  
    "acknowledge": true,  
}  

Open/Close Index

We can close a record for quite a while or later can open it. The open/close API permits us to play out these procedure on records. A shut record implies that the file is obstructed for read/compose activity and there is no upward on bunch aside from keeping up with its metadata. This shut record can be opened at whatever point you need and begin the typical cycle. See the underneath steps how open and close a file - 1. Go to the outline tab that contains the quantity of records made by you. Here, you will see two drop-down buttons Info and Action with each list.



2. Click on the Action button whose list you need to close and afterward on Close button.



3. A Popup will show up to you where click on the OK button.



4. Now, you will see your selected index is closed.



5. Click on the Action drop-down list to reopen the closed index and click on the Open button.



6. Now, you can see that the index starts working normally.



Index Exist

By sending a get demand, the presence of a list still up in the air. Assuming the HTTP reaction is 202, list exists and on the off chance that the return reaction is Error 404, the record doesn't exist. A list can likewise be opened and shut utilizing a question demand. See the model underneath - Close index

POST http://localhost/9200/book/  
_close  
{ }  
By executing this query, we will get below response-

{  
    "acknowledge": true,  
    "shards_acknowledge": true,  
    "indices": {  
        "book": {  
            "closed": true  
        }  
    }  
}     


Index Aliases

This API permits us to make a nom de plume for a list. To make a straightforward moniker, use _alias catchphrase or for complex pseudonym use _aliases. Recollect that a pseudonym name can't be equivalent to the record name. Along these lines, consistently give an alternate name to new pseudonyms. See the accompanying model given beneath - For Example

POST http://localhost/9200/  
_aliases  
{  
   "actions": [  
    {   
      "add": {   
        "index" : "book1",   
        "alias" : "book_pri"   
      }  
    }  
  ]  
} 

By executing this query, we will get below response-

{  
    "acknowledge": true,  
}  

Get aliases

Now, you can get back the information about created aliases book_pri using GET request. Execute the below code to get all information for aliases - Copy Code

GET http://localhost/9200/book_pri/  
{ }  
By executing this query, we will get below response-

{  
    "book1": {  
     "aliases": {  
        "book_pri": { }  
       },  
          "mappings": { },  
          "settings": {  
        "index": {  
             "creation_date": "1594989636357",  
             "number_of_shards": "1",  
             "number_of_replicas": "1",  
             "uuid": "2cFc6jUyS4C6tvM8yk2Sg",  
            "version": {  
                "created": "7080099"  
            },  
              "provided_name": "book1"  
        }  
          }  
    }  
}     

Remove aliases

Eliminating a pseudonym is like adding a moniker to a file. We simply just have to put remove keyword at the place of add and execute the request. Look at the example given below - Copy Code

POST http://localhost/9200/  
_aliases  
{  
   "actions": [  
    {   
      "remove": {   
        "index" : "book1",   
        "alias" : "book_pri"   
      }  
    }  
  ]  
}  

By executing this query, we will get below response-

{  
    "acknowledge": true,  
}  

Analyze

This API assists us with breaking down the text passed in a variable. It breaks the text string and returns the tokens with token worth and offset esteem (i.e., begin offset and end offset>
. In elasticsearch, it permits the client to perform investigation without determining any file. Nonetheless, we can likewise examine the text with a record where the text will be dissected by the analyzer related with the file. Take a gander at the accompanying model for breaking down the text without indicating any record - Copy Code

GET http://localhost/9200/  
_analyze  
{  
   "analyzer" : "standard",  
   "text" : "You are reading this text at javatpoint"  
} 

By executing this query, we will get below response-

{  
"tokens": [  
{  
        "token": "You",  
        "start_offset": 0,  
        "end_offset": 3,  
        "type": ,  
        "position": 0  
    },  
{  
        "token": "are",  
        "start_offset": 4,  
        "end_offset": 7,  
        "type": ,  
        "position": 1  
    },  
{  
        "token": "reading",  
        "start_offset": 8,  
        "end_offset": 15,  
        "type": ,  
        "position": 2  
    },  
{  
        "token": "this",  
        "start_offset": 16,  
        "end_offset": 20,  
        "type": ,  
        "position": 3  
    },  
{  
        "token": "text",  
        "start_offset": 21,  
        "end_offset": 25,  
        "type": ,  
        "position": 4  
    },  
{  
        "token": "at",  
        "start_offset": 26,  
        "end_offset": 28,  
        "type": ,  
        "position": 5  
    },  
{  
        "token": "javatpoint",  
        "start_offset": 29,  
        "end_offset": 39,  
        "type": ,  
        "position": 6  
    }  
}     


Index Template

Record layouts are applied naturally when a file made. We can likewise characterize formats for record utilizing file layout API. See the model given underneath - Copy Code


PUT http://localhost/9200/_template/template1  
  
{  
   "template" : "te*",   
      "settings" : {  
         "number_of_shards" : 4  
   },  
      
   "mappings" : {  
      "type1" : {  
         "_source" : { "enabled" : false }  
      }  
   }  
}  

Index Settings

Add _settings watchword toward the finish of the URL to get list settings. See the model given beneath - Copy Code

GET http://localhost/9200/book1/
_settings
{ }

By executing this question, we will get beneath reaction

{
"book1": {
         "settings": {
        "file": {
             "creation_date": "15949944338635",
             "number_of_shards": "1",
             "number_of_replicas": "1",
             "uuid": "LisavEX7SAS5cKFIn3GTA",
            "rendition": {
                "made": "7080099"
            },
              "provided_name": "book"
        }
          }
    }
}


Index Stats

Details is represents Statistics. At times, we expect to investigate the measurements for a specific record. This API assists with finding the measurements for the record you need. For this, we simply have to utilize GET technique and annex the _stats watchword alongside list name in URL and afterward execute the question. See the model given underneath - Copy Code

GET http://localhost/9200/book/  
_stats  
{ } 

By executing this query, we will get below response-

{  
        "shard": {  
    "total": 2,  
    "successful": 1,  
    "failed": 0  
         },  
    "all": {  
       "primaries": {  
             "docs": {  
        "count": 1,  
        "deleted": 0  
         },  
         "store": {  
        "size_in_bytes": 7025  
          },  
          "indexing": {  
        "index_total": 0,  
        "index_time_in_millis": 0,  
        "index_current": 0,  
        "index_failed": 0,  
        "delete_total": 0,  
        "delete_time_in_millis": 0,  
        "delete_current": 0,  
        "noop_update_total": 0,  
        "is_throttled": false,  
        "throttle_time_in_millis": 0  
          }  
          .  
          .  
          .  
          .  
          "indicies": {  
        "book": {  
            "uuis": "LisavEX7SAS5cKFIn3GTS",  
                "primaries": {  
            "docs": {  
                "count": 1,  
                "deleted": 0  
            },  
               "store": {  
                    "size_in_bytes": 7025     
            },  
          .  
          .  
          .  
          .  
          "recovery": {  
        "current_as_source": 0  
        "current_as_target": 0,  
        "throttle_time_in_millis": 0  
          }  
    }  
       }  
}     

Index Flush

The flush API is utilized to clean the memory of file as well as inside exchange logs. It additionally relocates the information to file capacity. To play out this procedure on a record, utilize the _flush watchword. Fundamentally, it assists with flushing all the trash information from list memory. Copy Code

GET http://localhost/9200/book/  
_flush  
{ } 

By executing this query, we will get below response-

{  
        "shard": {  
    "total": 2,  
    "successful": 1,  
    "failed": 0  
         }  
}     

Index Refresh

  • In elasticsearch, invigorate is booked consequently however you can likewise revive the singular file physically utilizing this API.
  • The _refresh API makes every one of the information accessible until last activity performed.
  • It permits to revive at least one records unequivocally. Determine the record name you need to invigorate and annex the _refresh API in URL and execute the inquiry demand.
  • Remember to utilize GET strategy for fruitful execution of question.
Look at the example given below - Copy Code

GET http://localhost/9200/book/  
_refresh  
{ }  
By executing this query, we will get below response-

{  
        "shard": {  
    "total": 2,  
    "successful": 1,  
    "failed": 0  
         }  
}