# Updating entities indexed by Hibernate Search

**URL:** https://discuss.elastic.co/t/updating-entities-indexed-by-hibernate-search/348207
**Category:** Elasticsearch
**Created:** [November 29, 2023, 9:25am UTC](https://discuss.elastic.co/t/updating-entities-indexed-by-hibernate-search/348207 "2023-11-29T09:25:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Muhammad\_namjas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_namjas/32/126607_2.png) [@Muhammad\_namjas](https://discuss.elastic.co/u/Muhammad_namjas)
#### Post date: [November 29, 2023, 9:25am UTC](https://discuss.elastic.co/t/updating-entities-indexed-by-hibernate-search/348207/1 "2023-11-29T09:25:38Z")

</div>

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

```auto
{
	"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**

```auto
{
	"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**

```auto
{
	"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**

```auto
{
	"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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 27, 2023, 9:26am UTC](https://discuss.elastic.co/t/updating-entities-indexed-by-hibernate-search/348207/2 "2023-12-27T09:26:36Z")

</div>

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