How to add new item inside Array in elastic search?

Hi Guys,
I am new in Elastic Search, I want to add new object inside JArray, How I can achive this?

"OrgDetailsLst" : [
{
"EntityId" : 3,
"EntityDetailCode" : 0,
"EntityName" : "PlantCode",
"EntityCode" : "DRES",
"Level" : 0
},
{
"EntityId" : 5,
"EntityDetailCode" : 0,
"EntityName" : "CompanyCode",
"EntityCode" : "0061",
"Level" : 0
}]
I want to add new object inside OrgDetailsLst, please let me know how I can achive this?

Hi,

You can easily insert this message out in ES. Before inserting, you need to be sure of whether you want an object or nested type for the field OrgDetailsLst. The same document can than be inserted.

You can use ES index API (https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#_create_document_ids_automatically) for inserting.

{
  "OrgDetailsLst" : [
    {
      "EntityId" : 3,
      "EntityDetailCode" : 0,
      "EntityName" : "PlantCode", 
      "EntityCode" : "DRES",
      "Level" : 0
    },
    {
      "EntityId" : 5,
      "EntityDetailCode" : 0,
      "EntityName" : "CompanyCode",
      "EntityCode" : "0061",
      "Level" : 0
    }
  ]
}

Thanks mjunaidmuzammil for quick help.

I want to insert data in OrgDetailsLst array where its type as nestedtype.

Make sure you apply the mappings first with nested. By default object types will get created.

Ok.

Can you please show with some codebase if I want to add below object inside OrgDetailsLst
{
"EntityId" : 6,
"EntityDetailCode" : 10,
"EntityName" : "CompanyCode1",
"EntityCode" : "0062",
"Level" : 2
}

@Pankaj_Jadhav Are you looking to insert in an existing document or a new one?

In An existing document

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