Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

CAST supportsElasticsearch via its NoSQL for Java extension. Details about how this support is provided for Java source code is discussed below.

Supported Client Libraries

LibraryVersionSupported
TransportClientup to: 5.4.0

Image Modified

LowLevelRestClientup to: 6.0.1

Image Modified

HIghLevelRestClientup to: 6.2.4

Image Added

JestClientUp to: 6.3.0

Image Modified

Supported Operations

Links are created for transaction and function point needs:

Link typeSource and destination of link Methods supportedparentLink

Between Elasticsearch Cluster object and Elasticsearch Index object

useLinkBetween the caller .NET Class / Method objects and Elasticsearch Index objects
  • bulk
  • bulkAsync
  • performRequest
  • performRequestAsync
useInsertLink
  • index
  • prepareIndex
  • indexAsync
useDeleteLink
  • delete
  • prepareDelete

useSelectLink

  • get
  • prepareGet
  • multiGet
  • multigetAsync
  • prepareMultiGet
  • multiSearch
  • multisearchAsync
  • prepareMultiSearch
  • search
  • searchAsync
  • prepareSearch
  • searchScroll
  • searchScrollAsync
  • explain
  • prepareExplain
  • exists
  • existsAsync
  • execute
  • fieldCaps
useUpdateLink
OperationMethods Supported
Insertindex


Expand
prepareIndex
title
  • indexAsync
  • Update
    • update
    • prepareUpdate
    • updateAsync
    Select
    • get
    • prepareGet
    • multiGet
    • multigetAsync
    • prepareMultiGet
    • multiSearch
    • multisearchAsync
    • prepareMultiSearch
    • search
    • searchAsync
    • prepareSearch
    • searchScroll
    • searchScrollAsync
    • explain
    • prepareExplain
    • exists
    • existsAsync
    • fieldCaps
    • execute
    Delete 
    • delete
    • prepareDelete

    Objects

    ...

    Image Removed

    ...

    Image Removed

    ...

    Image Removed

    ...

    Image Removed

    ...

    Insert operations
    • org.elasticsearch.client.support.AbstractClient.prepareIndex
    • org.elasticsearch.client.RestHighLevelClient.index
    • org.elasticsearch.client.RestHighLevelClient.indexAsync


    Update


    Expand
    titleUpdate operations
    • org.elasticsearch.client.support.AbstractClient.prepareUpdate
    • org.elasticsearch.client.support.AbstractClient.update
    • org.elasticsearch.client.RestHighLevelClient.update
    • org.elasticsearch.client.RestHighLevelClient.updateAsync
    • org.springframework.data.elasticsearch.core.DocumentOperations.bulkUpdate


    Select


    Expand
    titleSelect operations
    • org.elasticsearch.client.support.AbstractClient.prepareExplain
    • org.elasticsearch.client.support.AbstractClient.prepareGet
    • org.elasticsearch.client.support.AbstractClient.prepareMultiGet
    • org.elasticsearch.client.RestHighLevelClient.multiGet
    • org.elasticsearch.client.RestHighLevelClient.multiGetAsync
    • org.elasticsearch.client.RestHighLevelClient.multiSearch
    • org.elasticsearch.client.RestHighLevelClient.multiSearchAsync
    • org.elasticsearch.client.support.AbstractClient.get
    • org.elasticsearch.client.support.AbstractClient.explain
    • org.elasticsearch.client.RestHighLevelClient.search
    • org.elasticsearch.client.RestHighLevelClient.searchAsync
    • org.elasticsearch.client.RestHighLevelClient.searchScroll
    • org.elasticsearch.client.RestHighLevelClient.searchScrollAsync
    • org.elasticsearch.client.RestHighLevelClient.exists
    • org.elasticsearch.client.RestHighLevelClient.existsAsync
    • org.elasticsearch.client.RestHighLevelClient.get
    • org.elasticsearch.client.RestHighLevelClient.getAsync


    Delete 


    Expand
    titleDelete operations
    • org.elasticsearch.client.support.AbstractClient.prepareDelete
    • org.elasticsearch.client.support.AbstractClient.delete
    • org.elasticsearch.client.RestHighLevelClient.delete
    • org.elasticsearch.client.RestHighLevelClient.deleteAsync


    Objects

    Icon Description

    Image Added

    Java Elasticsearch Cluster

    Image Added

    Java Elasticsearch Index

    Image Added

    Java Unknown Elasticsearch Cluster

    Image Added

    Java Unknown Elasticsearch Index

    Links

    Links are created for transaction and function point needs:

    Link typeSource and destination of link Methods supported
    belongsTo

    From Java Elasticsearch Index object to Java Elasticsearch Cluster object


    useLinkBetween the caller .NET Class / Method objects and Java Elasticsearch Index objects


    • bulk
    • bulkAsync
    • performRequest
    • performRequestAsync
    useInsertLink
    • index
    • prepareIndex
    • indexAsync
    useDeleteLink
    • delete
    • prepareDelete

    useSelectLink

    • get
    • prepareGet
    • multiGet
    • multigetAsync
    • prepareMultiGet
    • multiSearch
    • multisearchAsync
    • prepareMultiSearch
    • search
    • searchAsync
    • prepareSearch
    • searchScroll
    • searchScrollAsync
    • explain
    • prepareExplain
    • exists
    • existsAsync
    • execute
    • fieldCaps
    • executeAsync
    useUpdateLink
    • update
    • prepareUpdate
    • updateAsync


    What results can you expect?

    Once the analysis/snapshot generation has completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

    Cluster and Index creation

    ...

    titleCluster and index creation

    ...

    languagejava
    titleCluster and Index creation

    ...

    shown below.

    Cluster and Index creation

    Expand
    titleCluster and index creation


    Code Block
    languagejava
    titleCluster and Index creation
     public test() throws UnknownHostException {
        	Settings setting = Settings.builder()
                    .put("cluster.name", "cluster1")
                    .put("client.transport.sniff", true).build();
            this.client = new PreBuiltTransportClient(setting)
                    .addTransportAddresses(new InetSocketTransportAddress(InetAddress.getByName(host), 9300),new InetSocketTransportAddress(InetAddress.getByName(host), 9301));
     }
    


    Code Block
    languagejava
    titlecluster creation
    public class restClientConnection {
    
    	private HttpHost httpHost;
    	private RestClient restClient;
    	private static HttpHost httpHost2 = new HttpHost("localhost",9303,"http");
    	
    	public restClientConnection(String host, int port, String protocol) {
    		
    		this.httpHost = new HttpHost(host, port, protocol);
    	}
    	
    	public RestClient connect() {
    		
    		this.restClient = RestClient.builder(this.httpHost,httpHost2).build();
    		return this.restClient;
    		
    	}
    }

    Image AddedImage Added

    Insert Operation

    Expand
    titleInsert Operation


    Code Block
    languagec#
    titleIndexDocument
     public String insertid(@PathVariable final String id) throws IOException {
    
            IndexResponse response = this.client.prepareIndex("person", "id", id)
                    .setSource(jsonBuilder()
                            .startObject()
                            .field("fname", "shakeel")
                            .field("fplace", "bangalore" )
                            .field("fteamName", "R&D")
                            .endObject()
                    )
                    
                    .get();
            return response.getResult().toString();
        }


    Code Block
    languagec#
    titleIndexDocumentAsync
    public String insertpid(@PathVariable final String id) throws IOException {
    
            IndexResponse response = this.client.prepareIndex()
            		.setIndex("person")
            		.setType("id")
            		.setId(id)
                    .setSource(jsonBuilder()
                            .startObject()
                            .field("fullname", "shakeel")
                            .field("age", "31" )
                            .field("qualification", "graduate")
                            .endObject()
                    )
                    
                    .get();
            return response.getResult().toString();
        }
    

    Image AddedImage Added

    Update Operation

    Expand
    titleUpdate Operation
    Expand
    titleInsert Operation


    Code Block
    languagec#
    titleUpdate
     public String update1(@PathVariable final String id) throws IOException {
    
            UpdateRequest updateRequest = new UpdateRequest();
            updateRequest.index("employee")
                    .puttype("cluster.name", "cluster1"id")
                    .put("client.transport.sniff", true).build();id(id)
              this.client = new PreBuiltTransportClient(setting)   .doc(jsonBuilder()
                 .addTransportAddresses(new InetSocketTransportAddress(InetAddress.getByName(host), 9300),new InetSocketTransportAddress(InetAddress.getByName(host), 9301));  } 
    Code Block
    languagejava
    titlecluster creation
    public class restClientConnection {  	private HttpHost httpHost;
    	private RestClient restClient;
    	private static HttpHost httpHost2 = new HttpHost("localhost",9303,"http");
    	
    	public restClientConnection(String host, int port, String protocol) {
    		
    		this.httpHost = new HttpHost(host, port, protocol);
    	}
    	
    	public RestClient connect() {
    		
    		this.restClient = RestClient.builder(this.httpHost,httpHost2).build();
    		return this.restClient;
    		
    	}
    }

    Image RemovedImage Removed

    Insert Operation

    Expand
    titleUpdate Operation
    Code Block
    languagec#
    titleIndexDocument
     public String insertid(@PathVariable final String id) throws IOException { .startObject()
                            .field("gender", "male")
                            .endObject());
            try {
                IndexResponseUpdateResponse responseupdateResponse = this.client.update(updateRequest).prepareIndex("person", "id", id)
      get();
                 System.out.setSourceprintln(jsonBuilderupdateResponse.status());
                return updateResponse.status().toString();
            } catch .startObject()InterruptedException | ExecutionException e) {
                System.out.println(e);
            .field("fname", "shakeel")}
            return "Exception";
        }


    Code Block
    languagec#
    titleUpdate
     public String update1(@PathVariable final String id) throws IOException {
    
    .field("fplace", "bangalore" )      UpdateRequest updateRequest = new UpdateRequest();
            updateRequest.index("employee")
         .field("fteamName", "R&D")           .type("id")
                    .endObjectid(id)
                    .doc(jsonBuilder()
                            .startObject()
             .get();           return response.getResult().toString();   .field("gender",  }
    Code Block
    languagec#
    titleIndexDocumentAsync
    public String insertpid(@PathVariable final String id) throws IOException {"male")
                         IndexResponse response = this.client.prepareIndexendObject());
            		.setIndex("person")
    try {
           		.setType("id")     UpdateResponse updateResponse   		.setId(id)= this.client.update(updateRequest).get();
                    .setSource(jsonBuilder()System.out.println(updateResponse.status());
                return updateResponse.status().toString();
            } catch .startObject()InterruptedException | ExecutionException e) {
                        .field("fullname", "shakeel")System.out.println(e);
            }
            return "Exception";
         .field("age", "31" )
      }


    Code Block
    languagejava
    titleUpdate Execute
    public String execute() throws IOException {
        	UpdateRequest updateRequest = new UpdateRequest();
                .field("qualification", "graduateupdateRequest.index("person")
                    .type("id")
           .endObject()         .id("123")
           )         .doc(jsonBuilder()
                            .getstartObject();
              return response.getResult().toString();     }
    

    Image RemovedImage Removed

    Update Operation

    Code Block
    languagec#
    titleUpdate
     public String update1(@PathVariable final String id) throws IOException {        .field("gender", "male")
                        UpdateRequest updateRequest = new UpdateRequest.endObject());
        	UpdateResponse gResponse   updateRequest.index("employee")= client.execute(UpdateAction.INSTANCE,updateRequest).actionGet();
        	System.out.println(gResponse.toString());
            return   gResponse.typetoString("id");
                    .id(id)
      }

    Image AddedImage Added

    Select Operation 

    Expand
    titleSelect Operation


    Code Block
    languagec#
    titleSelect
    public String explain1() throws IOException {
        	ExplainRequest explainRequest =       .doc(jsonBuilder()new ExplainRequest("person","id","123");
        	QueryBuilder queryBuilder           = QueryBuilders.matchQuery("lastname","khan");
        	explainRequest =  explainRequest.startObjectquery(queryBuilder);
        	ExplainResponse eResponse = client.explain(explainRequest).actionGet();
        	System.out.println(eResponse.getExplanation().getDescription());
               .field("gender", "male")return eResponse.getExplanation().getDescription();
        }
    
    public String fieldcap() throws IOException {
        	FieldCapabilitiesRequest fRequest = new FieldCapabilitiesRequest();
        	fRequest.endObjectfields("name").indices("employee","person");
        	FieldCapabilitiesResponse fResponse   try {
            = client.fieldCaps(fRequest).actionGet();
       UpdateResponse updateResponse = this.client.update(updateRequest).get( 	System.out.println(fResponse.get().toString());
            return    System.out.println(updateResponse.status());
          fResponse.get().toString();
        }

    Image AddedImage AddedImage Added

    Delete Operation

    Expand
    titleDelete Operation


    Code Block
    languagec#
    titleDelete
     public String delete1(@PathVariable final String id) {
    
        return updateResponse.status().toString();   DeleteResponse deleteResponse = client.prepareDelete("employee",   } catch (InterruptedException | ExecutionException e) {
      "id", id).get();
    
            System.out.println(e(deleteResponse.getResult().toString());
            }
    return deleteResponse.getResult().toString();
           return "Exception";
        }
    Code Block
    languagec#
    titleUpdate
     public String update1(@PathVariable final String id) throws IOException {
    
            UpdateRequest updateRequest = new UpdateRequest();
            updateRequest.index("employee")
                    .type("id")
        }

    Image Added

    Jest Elasticsearch Java Client

    Info
    APIs such as execute and executeAsync are used to perform all the CRUD operations. To identify which operation to be performed, type of Builder Request is analyzed.


    Expand
    titleInsert Operation


    Code Block
    languagejava
    public static void main(String[] args) throws IOException {
    	 	// Demo the JestClient
            JestClient jestClient = .idjestClient(id);
    		// Index a document from String
            ObjectMapper mapper = new .doc(jsonBuilderObjectMapper();
            JsonNode employeeJsonNode = mapper.createObjectNode()
                .startObject()    .put("name", "Michael  Pratt")
                     .fieldput("gendertitle", "maleJava Developer")
                    .put("yearsOfService", 2)
          .endObject());         try {
      .set("skills", mapper.createArrayNode()
              UpdateResponse updateResponse = this.client.update(updateRequest).get();             System.out.println(updateResponse.status());.add("java")
                return updateResponse.status().toString();         } catch (InterruptedException | ExecutionException e) {.add("spring")
                    System.out.println(e);         }.add("elasticsearch"));
             return "Exception";
        }jestClient.execute(new Index.Builder(employeeJsonNode.toString()).index("employees").build());
    }

    Image Added


    Expand
    titleDelete Operation


    Code Block
    languagejava
    titleUpdate Execute
    public String execute(public static void main(String[] args) throws IOException {
    	 	// Demo the JestClient
            JestClient jestClient = jestClient();
    		UpdateRequest// updateRequestDelete =documents
    new UpdateRequest();       jestClient.execute(new  updateRequestDelete.Builder("2") .index("personemployees")                 .type("id")
      .build());
    }

    Image Added


    Expand
    titleUpdate Operation


    Code Block
    languagejava
    public static void main(String[] args) throws IOException {
    	 	// Demo the JestClient
            JestClient jestClient =   .id("123")
                    .doc(jsonBuilder()
     jestClient();
    		// Update document
            employee.setYearsOfService(3);
            jestClient.execute(new Update.Builder(employee).index("employees").id("1").build());
    }

    Image Added


    Expand
    titleSelect Operation


    Code Block
    languagejava
    public static void .startObject(main(String[] args) throws IOException {
    	 	// Demo the JestClient
            JestClient jestClient       .field("gender", "male")
                            .endObject());= jestClient();
    		// Read document by ID
            	UpdateResponseEmployee gResponsegetResult = clientjestClient.execute(UpdateAction.INSTANCE,updateRequest).actionGet();
        	System.out.println(gResponse.toString());
            return gResponse.toString();
        }

    Image RemovedImage Removed

    ...

    new Get.Builder("employees", "1").build()).getSourceAsObject(Employee.class);
    }

    Image Added


    Expand
    titleSelect OperationBulk Operations
    Expand
    titleDelete Operation


    Code Block
    title
    languagec#javaSelect
    public static void main(String[] explain1(args) throws IOException {
    	 	// Demo  	ExplainRequest explainRequestthe JestClient
            JestClient jestClient = new ExplainRequest("person","id","123"jestClient();
    
    		// Bulk operations
     	QueryBuilder queryBuilder = QueryBuilders.matchQuery("lastname","khan");    Employee 	explainRequestemployeeObject1 = new explainRequest.queryEmployee(queryBuilder);
         	ExplainResponse eResponse = client.explain(explainRequest).actionGet(); employee.setName("John Smith");
            	System.out.println(eResponse.getExplanation().getDescription()employee.setTitle("Python Developer");
            return eResponseemployee.getExplanation().getDescription(setYearsOfService(10);
          }  public String fieldcap() throws IOException {employee.setSkills(Arrays.asList("python"));
    
            	FieldCapabilitiesRequestEmployee fRequestemployeeObject2 = new FieldCapabilitiesRequestEmployee();
          	fRequest.fields("name").indices("employee","person  employee.setName("Kate Smith");
         	FieldCapabilitiesResponse fResponse = clientemployee.fieldCaps(fRequest).actionGet();setTitle("Senior JavaScript Developer");
            	System.out.println(fResponse.get().toString())employee.setYearsOfService(10);
            return fResponseemployee.getsetSkills()Arrays.toString(asList("javascript", "angular"));
    
        }

    Image RemovedImage RemovedImage Removed

    Delete Operation

    Code Block
    languagec#
    titleDelete
     public String delete1(@PathVariable final String id) {    jestClient.execute(new Bulk.Builder().defaultIndex("employees")
                 DeleteResponse deleteResponse = client.prepareDelete("employee", "id", id).get();addAction(new Index.Builder(employeeObject1).build())
                    System.out.println(deleteResponse.getResult().toString());addAction(new Index.Builder(employeeObject2).build())
                    return deleteResponse.getResult().toString();
        }

    Image Removed

    Evolution

    ...

    .addAction(new Delete.Builder("3").build()) .build());
    }

    Image Added

    Limitations

    • APIs such as bulk (only for Transport Client, High Level Client) and performRequst result in useLinks
    • Bulk API used in Jest Client always results in appropriate CRUD links with unknown Index.
    • Multiple clusters used for CRUD operations are not supported. Only first found cluster is used.

    Future development

    • Resolving clusters used for CRUD operations when multiple clusters are present in the project.