Home > Mobile >  OpenSearch/ElasticSearch Error: unknown query [query]
OpenSearch/ElasticSearch Error: unknown query [query]

Time:10-22

I am trying to run a request against AWS OpenSearch with the _update_by_query plugin. In my code (below) I am trying to update the value of the column "ccstatus" to the string "NULL" wherever it is Null (or not specified). However when I try to run it I get the following error:

{'error': {'root_cause': [{'type': 'parsing_exception', 'reason': 'unknown query [query]', 'line': 1, 'col': 19}], 'type': 'parsing_exception', 'reason': 'unknown query [query]', 'line': 1, 'col': 19, 'caused_by': {'type': 'named_object_not_found_exception', 'reason': '[1:19] unknown field [query]'}}, 'status': 400}

Here is my current Python code:

  update_query = {
    "script": {
      "source": "ctx._source.ccstatus = 'NULL'",
      "lang": "painless"
    },
    "query": {
     "match": {
      "ccstatus": None
    }
  }
}
    
update_result = requests.post("https://search-my-test-domain.us-east-1.es.amazonaws.com/temp_test_index/_update_by_query", auth=(username, password), data=json.dumps({"query":update_query}), headers=headers).json()

print (update_result)

What am I doing wrong? I am using OpenSearch 2.3.

CodePudding user response:

You need to change this part

data=json.dumps({"query":update_query})

to just

data=json.dumps(update_query)
  • Related