Updating entities indexed by Hibernate Search

I created a new entity connected to Hibernate Elastic Search and indexed it. Upon retrieving the indexed data, I noticed that updating the entity using the student ID resulted in deleting the existing data and re-inserting the updated data. To preserve the existing data along with the updated data, I need to merge the updated data with the existing data before indexing the entity.

Student insertion request

{
	"studentId": "1",
	"studentMark": "10",
	"studentName": "LMN",
	"data": [
		{
			"id": "1",
			"mark": "10",
			"name": "ABC",
			"status": "Inprogress"
		},
		{
			"id": "5",
			"mark": "10",
			"name": "XYZ",
			"status": "READY_TO_PROCESS"
		}
	]
}

Upon completing the data insertion, I fetched the latest data from the Elasticsearch server.
Response

{
	"took": 8,
	"timed_out": false,
	"_shards": {
		"total": 1,
		"successful": 1,
		"skipped": 0,
		"failed": 0
	},
	"hits": {
		"total": {
			"value": 1,
			"relation": "eq"
		},
		"max_score": 1.0,
		"hits": [
			{
				"_index": "student-000001",
				"_type": "_doc",
				"_id": "1",
				"_score": 1.0,
				"_source": {
					"data": [
						{
							"id": "1",
							"mark": "10",
							"name": "ABC",
							"status": "Inprogress"
						},
						{
							"id": "5",
							"mark": "10",
							"name": "XYZ",
							"status": "READY_TO_PROCESS"
						}
					],
					"studentId": "1",
					"studentMark": "10",
					"studentName": "LMN",
					"_entity_type": "StudentEntity"
				}
			}
		]
	}
}

Update the entity using the student ID.
Request

{
	"studentId": "1",
	"studentMark": "10",
	"studentName": "OPQ",
	"data": [
		{
			"id": "1",
			"mark": "10",
			"name": "HIJ",
			"status": "READY_TO_PROCESS"
		}
	]
}

After updating the data, I retrieved it again from the Elasticsearch server to verify the changes.
Response

{
	"took": 8,
	"timed_out": false,
	"_shards": {
		"total": 1,
		"successful": 1,
		"skipped": 0,
		"failed": 0
	},
	"hits": {
		"total": {
			"value": 1,
			"relation": "eq"
		},
		"max_score": 1.0,
		"hits": [
			{
				"_index": "student-000001",
				"_type": "_doc",
				"_id": "1",
				"_score": 1.0,
				"_source": {
					"data": [
						{
							"id": "1",
							"mark": "10",
							"name": "HIJ",
							"status": "READY_TO_PROCESS"
						}
					],
					"studentId": "1",
					"studentMark": "10",
					"studentName": "OPQ",
					"_entity_type": "StudentEntity"
				}
			}
		]
	}
}

i found that after updating the entity defiantly its deleting the existing data and re-inserting the new changes.
How to avoid this change. i need to get existing as well as the updated data. Please help me too fix this issue

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.