How to do Upsert Operation in OpenSearch

We will learn how to do upsert operation in OpenSearch. There are couple of ways to do it, one using Index operation & another using Update operation. But how they work is different. So we will have to choose carefully based on our use case. Upsert using Index operation: Index operation by default does upsert. … Read more

How to Write OpenSearch Bulk Operation Using Java SDK

Here we will learn the basic code to do bulk operation in OpenSearch using Java SDK. We will need below dependencies in our Gradle project. This is part of build.gradle file. implementation ‘org.opensearch.client:opensearch-rest-client: 2.3.0’ implementation ‘org.opensearch.client:opensearch-java:2.0.0’ For maven projects, we need to add the dependencies in pom.xml file. As we know, OpenSearch provides bulk operation … Read more

How to Write OpenSearch Multi-Match Query in Java

Here we will see how to write OpenSearch multi-match query using Java SDK. OpenSearch multi-match query is supported for String type fields only. We will write code in Java to implement that. Also, we will write some Java code which can be used to emulate multi-match query for non-String data type fields like Integer, Long, … Read more

How to Instantiate OpenSearch Client in Java

Here we will learn how to create OpenSearch client using Java SDK. We will see how to connect to an OpenSearch cluster from a Java application for both AWS & non-AWS environments. OpenSearchClient for non-AWS environment: For a Gradle project, we need to add below dependencies in build.gradle file. For maven project, we would need … Read more

How to Mock Java Enum or Final Class Without PowerMock

First things first. Here we won’t be discussing mocking of Java enum or final class using PowerMock framework. That is already discussed in tons of places & one of the main reason why people tend to use PowerMock.Here we will be discussing mocking of enum or final classes with Mockito framework only. The feature has … Read more

Mocked Dependency Object Is Null After Using Mockito @InjectMocks Annotation

Let me explain the problem first. We have a Java class under test. We are using Junit with Mockito framework to write the unit test cases.We have annotated our test class with @InjectMocks annotation as below: @InjectMocks private TestClass testClass; @Mock private Dependency1 dependency1; @Mock private Dependency2 dependency2; That should inject mocked dependencies to the … Read more

Log When JDBC Connection Is Acquired And Released

We are fond of one db session per request pattern. For web applications with JPA & Hibernate, it is good strategy in common cases. But for some long-running requests (definition of long-running depends on your use case, maybe 500 ms or 2 s), we need to tweak when we are actually acquiring a db connection … Read more