Remove an object from an array


#1

Hey,

I want to remove an object (which's starting "activityId": 344485} in the array "projet-line" here :

{
"took": 9,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "projectsaduneo",
"_type": "doc",
"_id": "177182",
"_score": 1,
"_source": {
"id": 177182,
"code": "Activité internes Développement-00101",
"opportunityManagerId": "171074",
"opportunityManagerValue": "gestion",
"currentDate": "2018-05-11",
"projet-line": [
{
"activityId": 344262,
"activityValue": "Intégration continue",
"typeId": 170476,
"typeValue": "Temps"
},
{
"activityId": 344485,
"activityValue": "Définition charte graphique",
"employeeProfileId": 171174,
"employeeProfileValue": "Développeur Front",
"typeId": 170476,
"typeValue": "Temps"
}]
}
}]
}}

but I don't know how I can access to "projet-line" and remove object : "activityId": 344485.

If somebody know the answer please help me. Thanks :slight_smile:


(Alexander Reelsen) #2

please take the time to properly format your message using markdown, as this forum has excellent support for code snippets.

Can you also explain what exactly your problem is? You can store a document a second time (just with the appropriate fields removed) or use the update API


#3

Hey, I will try again to explaiin what I want to do. So I have the database in elasticsearch witch name is projectsaduneo. I have also one project with the id is : 179508 with the différents fields like : code, label, entityId, ..., and projet-line (which is an array objects with the différents fields : activityId, activityValue, ..., typeValue).

{
    "took": 14,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 1,
        "hits": [
            {
                "_index": "projectsaduneo",
                "_type": "doc",
                "_id": "179508",
                "_score": 1,
                "_source": {
                    "id": 179508,
                    "code": "Dashboards automatisés -00237",
                    "label": "Dashboards automatisés ",
                    "entityId": "150989",
                    "entityValue": "150989",
                    "projectManagerId": "171007",
                    "projectManagerValue": "mfehrenbacher",
                    "opportunityManagerId": "171074",
                    "opportunityManagerValue": "gestion",
                    "currentPosition": "-100",
                    "projectInProgress": "false",
                    "projectOutOfDate": "true",
                    "realStartDate": "2017-12-21T00:00:00",
                    "realEndDate": "2018-05-11T00:00:00",
                    "currentDate": "2018-05-17",
                    "projet-line": [
                        {
                            "activityId": 347824,
                            "activityValue": "Configuration avec Kibana",
                            "employeeProfileId": 171175,
                            "employeeProfileValue": "Développeur back",
                            "typeId": 170476,
                            "typeValue": "Temps"
                        },
                        {
                            "activityId": 347822,
                            "activityValue": "Dashboards automatisés à Suppirmer",
                            "employeeProfileId": 171175,
                            "employeeProfileValue": "Développeur back",
                            "typeId": 170476,
                            "typeValue": "Temps"
                        },
                        {
                            "activityId": 347825,
                            "activityValue": "Génération de fichiers Excel",
                            "employeeProfileId": 171175,
                            "employeeProfileValue": "Développeur back",
                            "typeId": 170476,
                            "typeValue": "Temps"
                        },
                        {
                            "activityId": 347823,
                            "activityValue": "Interfacage avec Everwin",
                            "employeeProfileId": 171175,
                            "employeeProfileValue": "Développeur back",
                            "typeId": 170476,
                            "typeValue": "Temps"
                        },
                        {}
                    ]
                }
            }
        ]
    }
}

So now, I vould like to remove one of my objects in the fields "projet-line", I chose this one :

                          {
                                "activityId": 347823,
                                "activityValue": "Interfacage avec Everwin",
                                "employeeProfileId": 171175,
                                "employeeProfileValue": "Développeur back",
                                "typeId": 170476,
                                "typeValue": "Temps"
                            }

but I don't know how I can access in this object to remove this. For remove my project I use this request :

   http://localhost:9200/projectsaduneo/_bulk(with the POST method) : 

   {"delete":{"_id":179508,"_type":"doc","_index":"projectsaduneo"}}

Now Iwant remove object that I wrote before. Can you give me an advice to delete him ?

I hope that I was clear in my explanation.

Thanks for yuor answer !


(system) #4

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