0

Here is my index(sub_application), I need to pass values to the keys (id, name) in approved_by object. I tried in different ways nothing workout

{
  "settings": {
  },
  "mappings": {
    "sub_application": {
      "properties": {
        "archived_at": {
          "type": "date"
        },
        "approved_by": {
           "properties": {
              "name": {
                 "type": "text"
               },
              "id": {
                "type": "text"
               }
      }
    }
      }
    }
  }
}

Attempt1:

     for info in sub_application_obj['hits']['hits']:
                print(info)
                item = info['_source']
                current_employer = item['approved_by']
                client.update(index='sub_application',
                  doc_type='sub_application',
                  body={'doc': { 
                         current_employer['name']: approved_user,
                         current_employer['id']: approved_userid
                             }},
                    id=info['_id'])

   

Attempt2:

    client.update(index='sub_application',
                  doc_type='sub_application',
                  body={'doc': { 
                         ['approved_by']['name']: approved_user,
                         ['approved_by']['id']: approved_userid 
                             }},
                    id=info['_id'])

Attemp3:

   client.update(index='sub_application',
              doc_type='sub_application',
              body={'doc': { 
                     ['approved_by.name']: approved_user,
                     ['approved_by.id']: approved_userid 
                         }},
                id=info['_id'])

I need to pass approved_user and approved_userid to the keys name, id in approved_by object. I tried but didn't get it,please help me guys.

1 Answer 1

0

In Elastic a nested field is an array of object. Here you just need to pass data to a sub object.

client.update(index='sub_application',
              doc_type='sub_application',
              body={
                 'doc': { 
                    'approved_by': {'name': approved_user, 'id': approved_userid}
                 }
              },
              id=info['_id'])

and for a nested object :

client.update(index='sub_application',
              doc_type='sub_application',
              body={
                 'doc': { 
                    'approved_by': [{'name': approved_user, 'id': approved_userid}]
                 }
              },
              id=info['_id'])

You can have more information here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.