1
votes

I am beginner programmer in python. Now I have integrated Elasticseach 6.8.1 version with python and now I have to delete data from elasticsearch using pyhton language. For this I have written following query

 query = {'bool':{'must':[
                {'term':{'db_id':25}},
                {'terms': {'type': ['user_likes','likes']}}
            ]}}
es_client.delete_by_query(index="user_likes", doc_type='doc', body=query)

When I run this query I get following error

{RequestError}RequestError(400, 'parsing_exception', 'Unknown key for a START_OBJECT in [bool].')

I did not found in example the how I can use must with multiple condition for delete_by_query. how I can execute this query for delete_by_query?

1
this error is not bcoz of any mistake in python , there is mistake in your query . please share any 1 document from your elasticsearch index & what is your expected output. - Sowjanya R Bhat
@SowjanyaRBhat I have updated the query I simply need to delete the data by using this I query which I write - Rizwan Saleem

1 Answers

2
votes

Try to change what you have declared as query to this :

 query = {'query': 
           {'bool':
              {'must':[
                {'term':{'db_id':int(model['id'])}},
                {'terms': {'type': ['user_likes','likes']}}
        ]}}
    }

What I have done is just added query parameter - inside which bool has to appear, but you have directly kept bool I am guessing that would be the problem. If it doesn't work still, provide more details about your data & expected output