in Technology by
What is Elasticsearch - Document APIs?

1 Answer

0 votes
by

Elasticsearch provides single document APIs and multi-document APIs, where the API call is targeting a single document and multiple documents respectively.

Index API

It helps to add or update the JSON document in an index when a request is made to that respective index with specific mapping. For example, the following request will add the JSON object to index schools and under school mapping −

PUT schools/_doc/5
{
   name":"City School", "description":"ICSE", "street":"West End",
   "city":"Meerut",
   "state":"UP", "zip":"250002", "location":[28.9926174, 77.692485],
   "fees":3500,
   "tags":["fully computerized"], "rating":"4.5"
}

On running the above code, we get the following result −

{
   "_index" : "schools",
   "_type" : "_doc",
   "_id" : "5",
   "_version" : 1,
   "result" : "created",
   "_shards" : {
      "total" : 2,
      "successful" : 1,
      "failed" : 0
   },
   "_seq_no" : 2,
   "_primary_term" : 1
}

Automatic Index Creation

When a request is made to add JSON object to a particular index and if that index does not exist, then this API automatically creates that index and also the underlying mapping for that particular JSON object. This functionality can be disabled by changing the values of following parameters to false, which are present in elasticsearch.yml file.

action.auto_create_index:false
index.mapper.dynamic:false

You can also restrict the auto creation of index, where only index name with specific patterns are allowed by changing the value of the following parameter −

action.auto_create_index:+acc*,-bank*

Note − Here + indicates allowed and – indicates not allowed.

Versioning

Elasticsearch also provides version control facility. We can use a version query parameter to specify the version of a particular document.

PUT schools/_doc/5?version=7&version_type=external
{
   "name":"Central School", "description":"CBSE Affiliation", "street":"Nagan",
   "city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],
   "fees":2200, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.3"
}

On running the above code, we get the following result −

{
   "_index" : "schools",
   "_type" : "_doc",
   "_id" : "5",
   "_version" : 7,
   "result" : "updated",
   "_shards" : {
      "total" : 2,
      "successful" : 1,
      "failed" : 0
   },
   "_seq_no" : 3,
   "_primary_term" : 1
}

Versioning is a real-time process and it is not affected by the real time search operations.

There are two most important types of versioning −

Internal Versioning

Internal versioning is the default version that starts with 1 and increments with each update, deletes included.

<h3 style="margin-t

Related questions

0 votes
    Which are the operations can be performed on a document using Elasticsearch?...
asked Jun 3, 2021 in Technology by JackTerrance
0 votes
    Apigee's API platform allows you to ____ your APIs. Secure Manage All the options Scale...
asked Sep 3, 2021 in Technology by JackTerrance
0 votes
    APIs are software interfaces that allow different applications to talk to one another. True False...
asked Sep 3, 2021 in Technology by JackTerrance
0 votes
    What are the test library APIs provided by the Robot Framework?...
asked Jul 10, 2021 in Technology by JackTerrance
0 votes
    Cassandra supports which of the below API's to retrieve and manipulate data (1)Client API (2)All the options (3)Thrift API (4)Avro...
asked May 7, 2021 in Technology by JackTerrance
0 votes
    What is one advantage that HTML5 APIs offer for modern Web design? (1)They enable users to view Flash content on ... (4)They enable users to view multimedia without plug-ins...
asked Apr 21, 2021 in Technology by JackTerrance
0 votes
    Cassandra supports which of the below API's to retrieve and manipulate data (1)Client API (2)All the options (3)Thrift API (4)Avro...
asked Apr 16, 2021 in Technology by JackTerrance
0 votes
    Why API's is used in cloud services?...
asked Dec 16, 2020 in Technology by JackTerrance
0 votes
+1 vote
    Enlist some common tests that are performed on APIs....
asked Oct 15, 2020 in Technology by JackTerrance
0 votes
    Elastic Search Questions and Answers...
asked Jul 11, 2022 in Technology by sandeepthukran
0 votes
    State an example of use cases of Elasticsearch Kibana?...
asked Jun 4, 2021 in Technology by JackTerrance
0 votes
    What do you understand by analyzer in Elasticsearch?...
asked Jun 3, 2021 in Technology by JackTerrance
0 votes
    What is Elasticsearch in Kibana?...
asked Jun 3, 2021 in Technology by JackTerrance
0 votes
    How to create Automatic Index in Elasticsearch?...
asked Dec 4, 2020 in Technology by JackTerrance
...