Add or update to a exists json in elastic search

How can I update/add data in ES

for example

{
appName:test,
notes:test notes,
bulkData:[
{
id:345345,
name:test,
data:[
{temp:1},
{temp;2}
]
}
]
}

now I want to add a few more data on bulkData(key), and also later want to add few more data on bulkData.data(key),
how can I achieve this without deleting the existing index

Thanks in advance

Hi @dadoonet
can you please help me on this

PUT index/_doc/1
{
  appName:test,
  notes:test notes,
  bulkData:[
  {
    id:345345,
    name:test,
    data:[
      {temp:1},
      {temp:2}
    ]
  }
  ]
}

Then

PUT index/_doc/1
{
  appName:test,
  notes:test notes,
  bulkData:[
  {
    id:345345,
    name:test,
    data:[
      {temp:1},
      {temp:2},
      {temp:3}
    ]
  }
  ]
}

Thanks @dadoonet

instead of carrying all the data, is there any possibility to push/update to specific key without carrying all the data

May be. With the update API. But I don't really recommend using it. Behind the scene, it will do anyway the same thing.
IMHO update by query is useful if you have very very big JSON documents to update and you want to limit the bandwidth usage.

Are your documents so big?

yes, its too large and even the ES API throwing an error with code 413, entity is too large

Could you share a typical document?

I'm just wondering if you designed your documents in the best way.

Below is the doc

   {
  "appName": "test",
  "notes": "test notes",
  "bulkData": [
    {
      "id": 345345,
      "name": "test",
      "data": [
        {
          "temp": 1
        },
        {
          "temp": 2
        }
      ]
    },
    {
      "id": 345345345435345,
      "name": "test",
      "data": [
        {
          "temp": 13453
        },
        {
          "temp": 2345
        },
        {
          "temp": 34534543513453
        },
        {
          "temp": 345436565675672300
        }
      ]
    }
  ]
}

and mappings

    {
    	"myindex": {
    		"mappings": {
    			"bulkUpsertData": {
    				"properties": {
    					"appName": {
    						"type": "text",
    						"fields": {
    							"keyword": {
    								"type": "keyword",
    								"ignore_above": 256
    							}
    						}
    					},
    					"notes": {
    						"type": "text",
    						"fields": {
    							"keyword": {
    								"type": "keyword",
    								"ignore_above": 256
    							}
    						}
    					},
    					"bulkData": {
    						"properties": {
    							"id": {
    								"type": "text",
    								"fields": {
    									"keyword": {
    										"type": "keyword",
    										"ignore_above": 256
    									}
    								}
    							},
    							"name": {
    								"type": "text",
    								"fields": {
    									"keyword": {
    										"type": "keyword",
    										"ignore_above": 256
    									}
    								}
    							},
    							"data": {
    								"properties": {
    									"temp": {
    										"type": "long"
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    }

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

Your document is not big enough to justify using the update API IMO.

updated/formatted the JSON

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