Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.11.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import com.iemr.common.identity.utils.IEMRApplBeans;

@SpringBootApplication
@ComponentScan(basePackages = {"com.iemr.common.identity"})
public class IdentityApplication extends SpringBootServletInitializer {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public Executor elasticsearchSyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

// Only 1-2 sync jobs should run at a time to avoid overwhelming DB/ES
executor.setCorePoolSize(5);
executor.setMaxPoolSize(10);
executor.setCorePoolSize(2);
executor.setMaxPoolSize(4);
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("es-sync-");
executor.setKeepAliveSeconds(60);
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(60);

// Handle rejected tasks
executor.setRejectedExecutionHandler((r, executor1) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public ResponseEntity<Map<String, Object>> advanceSearchBeneficiariesES(
logger.info("Search params = {}", searchParams);

String firstName = getString(searchParams, "firstName");
String middleName = getString(searchParams, "middleName");
String maritalStatus = getString(searchParams, "maritalStatus");
String lastName = getString(searchParams, "lastName");
Integer genderId = getInteger(searchParams, "genderId");
Date dob = getDate(searchParams, "dob");
Expand All @@ -115,9 +117,9 @@ public ResponseEntity<Map<String, Object>> advanceSearchBeneficiariesES(

Map<String, Object> searchResults =
idService.advancedSearchBeneficiariesES(
firstName, lastName, genderId, dob,
firstName, middleName, lastName, genderId, dob,
stateId, districtId, blockId, villageId,
fatherName, spouseName, phoneNumber,
fatherName, spouseName, maritalStatus, phoneNumber,
beneficiaryId, healthId, aadharNo,
userID, null, is1097
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

Expand All @@ -16,6 +17,9 @@
import java.util.Map;
import org.springframework.http.ResponseEntity;
import com.iemr.common.identity.utils.response.OutputResponse;

import co.elastic.clients.elasticsearch.ElasticsearchClient;

import com.iemr.common.identity.domain.MBeneficiarymapping;
import com.iemr.common.identity.service.elasticsearch.ElasticsearchIndexingService;

Expand All @@ -41,11 +45,17 @@ public class ElasticsearchSyncController {
@Autowired
private ElasticsearchIndexingService indexingService;

@Autowired
private ElasticsearchClient esClient;

@Value("${elasticsearch.index.beneficiary}")
private String beneficiaryIndex;

/**
* Start async full sync (RECOMMENDED for millions of records)
* Returns immediately with job ID for tracking
*
* Usage: POST http://localhost:8080/elasticsearch/sync/start
* Usage: POST http://localhost:8080/elasticsearch/start
*/
@PostMapping("/start")
public ResponseEntity<Map<String, Object>> startAsyncFullSync(
Expand Down Expand Up @@ -83,7 +93,7 @@ public ResponseEntity<Map<String, Object>> startAsyncFullSync(
/**
* Get job status by ID
*
* Usage: GET http://localhost:8080/elasticsearch/sync/status/1
* Usage: GET http://localhost:8080/elasticsearch/status/1
*/
@GetMapping("/status/{jobId}")
public ResponseEntity<Map<String, Object>> getAsyncJobStatus(@PathVariable Long jobId) {
Expand Down Expand Up @@ -120,7 +130,7 @@ public ResponseEntity<Map<String, Object>> getAsyncJobStatus(@PathVariable Long
/**
* Get all active jobs
*
* Usage: GET http://localhost:8080/elasticsearch/sync/active
* Usage: GET http://localhost:8080/elasticsearch/active
*/
@GetMapping("/active")
public ResponseEntity<List<ElasticsearchSyncJob>> getActiveJobs() {
Expand All @@ -131,7 +141,7 @@ public ResponseEntity<List<ElasticsearchSyncJob>> getActiveJobs() {
/**
* Get recent jobs
*
* Usage: GET http://localhost:8080/elasticsearch/sync/recent
* Usage: GET http://localhost:8080/elasticsearch/recent
*/
@GetMapping("/recent")
public ResponseEntity<List<ElasticsearchSyncJob>> getRecentJobs() {
Expand All @@ -142,7 +152,7 @@ public ResponseEntity<List<ElasticsearchSyncJob>> getRecentJobs() {
/**
* Resume a failed job
*
* Usage: POST http://localhost:8080/elasticsearch/sync/resume/1
* Usage: POST http://localhost:8080/elasticsearch/resume/1
*/
@PostMapping("/resume/{jobId}")
public ResponseEntity<Map<String, Object>> resumeJob(
Expand Down Expand Up @@ -173,7 +183,7 @@ public ResponseEntity<Map<String, Object>> resumeJob(
/**
* Cancel a running job
*
* Usage: POST http://localhost:8080/elasticsearch/sync/cancel/1
* Usage: POST http://localhost:8080/elasticsearch/cancel/1
*/
@PostMapping("/cancel/{jobId}")
public ResponseEntity<Map<String, Object>> cancelJob(@PathVariable Long jobId) {
Expand All @@ -194,10 +204,10 @@ public ResponseEntity<Map<String, Object>> cancelJob(@PathVariable Long jobId) {
}

/**
* LEGACY: Synchronous full sync (NOT recommended for large datasets)
* LEGACY: Synchronous full sync(NOT recommended for large datasets)
* Use /start instead
*
* Usage: POST http://localhost:8080/elasticsearch/sync/all
* Usage: POST http://localhost:8080/elasticsearch/all
*/
@PostMapping("/all")
public ResponseEntity<Map<String, Object>> syncAllBeneficiaries() {
Expand Down Expand Up @@ -232,7 +242,7 @@ public ResponseEntity<Map<String, Object>> syncAllBeneficiaries() {
/**
* Sync a single beneficiary by BenRegId
*
* Usage: POST http://localhost:8080/elasticsearch/sync/single/123456
* Usage: POST http://localhost:8080/elasticsearch/single/123456
*/
@PostMapping("/single/{benRegId}")
public ResponseEntity<Map<String, Object>> syncSingleBeneficiary(
Expand Down Expand Up @@ -268,7 +278,7 @@ public ResponseEntity<Map<String, Object>> syncSingleBeneficiary(
/**
* Check sync status - compare DB count vs ES count
*
* Usage: GET http://localhost:8080/elasticsearch/sync/status
* Usage: GET http://localhost:8080/elasticsearch/status
*/
@GetMapping("/status")
public ResponseEntity<SyncStatus> checkSyncStatus() {
Expand All @@ -289,7 +299,7 @@ public ResponseEntity<SyncStatus> checkSyncStatus() {
/**
* Health check endpoint
*
* Usage: GET http://localhost:8080/elasticsearch/sync/health
* Usage: GET http://localhost:8080/elasticsearch/health
*/
@GetMapping("/health")
public ResponseEntity<Map<String, Object>> healthCheck() {
Expand All @@ -304,7 +314,7 @@ public ResponseEntity<Map<String, Object>> healthCheck() {
/**
* Debug endpoint to check if a beneficiary exists in database
*
* Usage: GET http://localhost:8080/elasticsearch/sync/debug/check/123456
* Usage: GET http://localhost:8080/elasticsearch/debug/check/123456
*/
@GetMapping("/debug/check/{benRegId}")
public ResponseEntity<Map<String, Object>> checkBeneficiaryExists(
Expand Down Expand Up @@ -427,4 +437,26 @@ public ResponseEntity<OutputResponse> getIndexInfo() {
return ResponseEntity.status(500).body(response);
}
}

@PostMapping("/refresh")
public ResponseEntity<Map<String, Object>> refreshIndex() {
Map<String, Object> response = new HashMap<>();

try {
logger.info("Manual refresh requested");

esClient.indices().refresh(r -> r.index(beneficiaryIndex));

response.put("status", "success");
response.put("message", "Index refreshed - all data is now searchable");

return ResponseEntity.ok(response);

} catch (Exception e) {
logger.error("Refresh failed: {}", e.getMessage(), e);
response.put("status", "error");
response.put("message", "Refresh failed: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class BeneficiaryDocument {
@JsonProperty("firstName")
private String firstName;

@JsonProperty("middleName")
private String middleName;

@JsonProperty("lastName")
private String lastName;

Expand All @@ -28,6 +31,12 @@ public class BeneficiaryDocument {
@JsonProperty("spouseName")
private String spouseName;

@JsonProperty("maritalStatusID")
private Integer maritalStatusID;

@JsonProperty("maritalStatusName")
private String maritalStatusName;

@JsonProperty("age")
private Integer age;

Expand Down Expand Up @@ -58,6 +67,9 @@ public class BeneficiaryDocument {
@JsonProperty("abhaID")
private String abhaID;

@JsonProperty("abhaCreatedDate")
private String abhaCreatedDate;

@JsonProperty("familyID")
private String familyID;

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/iemr/common/identity/dto/BeneficiariesESDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class BeneficiariesESDTO {

@JsonProperty("firstName")
private String firstName;

@JsonProperty("middleName")
private String middleName;

@JsonProperty("lastName")
private String lastName;
Expand Down Expand Up @@ -56,6 +59,12 @@ public class BeneficiariesESDTO {
@JsonProperty("spouseName")
private String spouseName;

@JsonProperty("maritalStatusID")
private Integer maritalStatusID;

@JsonProperty("maritalStatusName")
private String maritalStatusName;

@JsonProperty("createdBy")
private String createdBy;

Expand All @@ -77,6 +86,9 @@ public class BeneficiariesESDTO {
@JsonProperty("abhaID")
private String abhaID;

@JsonProperty("abhaCreatedDate")
private String abhaCreatedDate;

@JsonProperty("familyID")
private String familyID;

Expand Down
Loading