title: How to update value of a field within a document in Elasticsearch using python
body: <p>I have this data stored in the <code>Elasticsearch</code> which is in this <code>json</code> format:</p>
  
  <pre><code>{
     "qna": [
        {
           "qid": "1",
           "question": [
              "How to use the tool"
           ],
           "answer": "Create and administer your questions Content Designer UI.",
           "votes": "0"
        },
        {
           "qid": "2",
           "question": [
              "How can I include attachements"
           ],
           "answer": "Add an image attachment to the item using the Content Designer.",
           "votes": "0"
        }
     ]
  }
  </code></pre>
  
  <p>Now I have written this code where when a <code>question</code> string is passed I am able to fetch the <code>answer</code> from Elasticsearch:</p>
  
  <pre><code>from elasticsearch import Elasticsearch
  
  def search_es(question,index_name):
  
      es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
  
      data = {
          "query": {
              "function_score":{
                  "query":{
  
                      "match": {
                          'question': question
                      }
                  },
                  "field_value_factor":{
                      "field":"votes",
                      "modifier":"log2p"
                  }
              }
          }
      }
      response = es.search(index=str(index_name).lower(), body=data)
      for items in response['hits']['hits']:
          score = items['_score']
          answer = source['a']
          score_answer.append([score,answer])
  
      score_answer.sort(key=lambda x: int(x[0]), reverse=True)
      # SELECT ONE ANSWER - TOP SCORED ANSWER
      print(score_answer[0][1])
      # CODE TO INCREASE VOTE OF THE SELECTED ANSWER
      increase_vote(score_answer[0][1])
  
  def increase_vote(answer):
      # IMPLEMENT CODE HERE
  </code></pre>
  
  <p>As you can see the <code>search_es()</code> extracts and selects the top scored <code>answer</code> field. <strong>Now what I want to do is implement a function that will update the <code>votes</code> field associated with the selected <code>answer</code> and increase it by 1</strong>. I looked around and found few posts related to <code>partial update</code> of documents like <a href="https://stackoverflow.com/questions/30598152/how-to-update-a-document-using-elasticsearch-py">this</a> but am unable to figure out a way on how to update the field as described in my scenario?</p>