The get,delete,bulk of the Javaapi of Elasticsearch

Source: Internet
Author: User

Elsasticsearch's Javaapi get

The Get API allows JSON-based document in the specified index to be obtained based on its ID. The following example obtains a JSON document (index of Twitter,type is tweet,id for value 1)

 
  
< Span class= "Typ" >getresponse   response  =   client   prepareget    "Twitter"      "tweet"      "1"  )  
          execute   ()  
          actionget 
 ();  
 
  

For more information on the get operation, you can view rest get docs

Threading Operations

The Get API allows you to set up threads to perform operations so that the actual execution of the API is performed on the same node (the API executes on a shard that is assigned on the same server).

Select a different thread to perform the operation on, or execute it on the calling thread (note that the API is still asynchronous). By default, operationThreaded The actions that are set to true This mean that the operation is performed on a different thread are as follows an example, set to False:

GetResponse response = Client.prepareget ("Twitter", "tweet", "1")
. setoperationthreaded (False)
. Execute ()
. Actionget ();

Elsasticsearch's Javaapi Delete

The Delete API allows you to delete the JSON document in the specified index based on its ID. The following example: Delete a JSON document (index is twitter,type to Tweet,id for value 1)

 
  
< Span class= "Typ" >deleteresponse   response  =   client   preparedelete    "Twitter"      "tweet"      "1"  )  
          execute   ()  
          actionget 
 ();  

For more information on the delete operation, view the delete API docs.

Threading Operations

The Delete API allows you to set up threads to perform operations so that the actual ginger execution API executes on the same node (the API executes on a shard that is assigned on the same server).

Select a different thread to perform the operation on, or execute it on the calling thread (note that the API is still asynchronous). By default, operationThreaded The actions that are set to true This mean that the operation is performed on a different thread are as follows an example, set to False:

Deleteresponse response = Client.preparedelete ("Twitter", "tweet", "1")
. setoperationthreaded (False)
. Execute ()
. Actionget ();

The bulk of the javaapi of Elasticsearch

The Bulk API can be used to retrieve and delete multiple data in a single request, and here is an example:

Import Static org . Elasticsearch . Common . xcontent . xcontentfactory .*;
Bulkrequestbuilderbulkrequest=Client.Preparebulk();


//either use Client#prepare, or use requests# to directly build Index/delete requests
bulkrequest . Add ( Client . Prepareindex ( "Twitter" , "tweet" , "1" )
         . SetSource ( Jsonbuilder ()
                     . StartObject ()
                         . Field ( "User" , "Kimchy" )
                         . Field ( "Postdate" , New Date ())
                         . Field ( "Message" , "trying out Elasticsearch" )
                     . EndObject ()
                   )
         );
bulkrequest.Add(Client.Prepareindex("Twitter","tweet","2")

         . SetSource ( Jsonbuilder ()
                     . StartObject ()
                         . Field ( "User" , "Kimchy" )
                         . Field ( "Postdate" , New Date ())
                         . Field ( "Message" , "another post" )
                     . EndObject ()
                   )
         );
BulkresponseBulkresponse=bulkrequest.Execute().Actionget();

if ( Bulkresponse . Hasfailures ()) {
     //process failures by iterating through per bulk response item
}

Original http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/get.html
http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/delete.html
http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/bulk.html
I hope that the translation is not misleading.

The get,delete,bulk of the Javaapi of Elasticsearch

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.