Elasticsearch delete_by_query wrong usage

2024/10/12 23:26:44

I am using 2 similar ES methods to load and delete documents:

result = es.search(index='users_favourite_documents',doc_type='favourite_document',body={"query": {"match": {'user': user}}})

And:

result = es.delete_by_query(index='users_favourite_documents',doc_type='favourite_document',body={"query": {"match": {'user': user}}})

First one works ok and returns expected records.
Second one throws Exception:

"TransportError(404,'{
\"found\":false,
\"_index\":\"users_favourite_documents\",
\"_type\":\"favourite_document\",
\"_id\":\"_query\",\"_version\":1,
\"_shards\":{\"total\":2,\"successful\":2,\"failed\":0}}')"

What am I doing wrong?

Answer

I'v used version 6.2.0 of the Elastic Stack and the use of the API works for deleting like this:

es.delete_by_query(index="index_name", doc_type='doc_type', body={"query":{"match": {"message": "message_value"}}})

if your value is INT remove the "" in message_value.

https://en.xdnf.cn/q/118145.html

Related Q&A

SQLAlchemy: Lost connection to MySQL server during query

There are a couple of related questions regarding this, but in my case, all those solutions is not working out. Thats why I thought of asking again. I am getting this error while I am firing below quer…

row to columns while keeping part of dataframe, display on same row

I am trying to move some of my rows and make the them columns, but keep a large portion of the dataframe the same.Resulting Dataframe:ID Thing Level1 Level2 Time OAttribute IsTrue Score Value 1 …

SQLAlchemy InvalidRequestError when using composite foreign keys

My table relationships in SQLAlchemy have gotten quite complex, and now Im stuck at this error no matter how I configure my relationship.Im a bit new to SQLAlchemy so Im not sure what Im doing wrong, b…

google search by google api in r or python

I want to search some thing (ex:"python language") in google by python or R and it will give me the list of links for that google search like:https://en.wikipedia.org/wiki/Python_(programming…

NumPy Wont Append Arrays

Im currently working on a neural network to play Rock-Paper-Scissors, but Ive run into an enormous issue.Im having the neural network predict what will happen next based on a history of three moves, wh…

(Django) Limited ForeignKey choices by Current User in UpdateView

I recently was able to figure out how to do this in the CreateView, but the same is not working for the UpdateView (Heres the original post on how to do it in the CreateView: (Django) Limited ForeignKe…

Merge list concating unique values as comma seperated retaining original order from csv

Here is my data:data.csvid,fname,lname,education,gradyear,attributes 1,john,smith,mit,2003,qa 1,john,smith,harvard,207,admin 1,john,smith,ft,212,master 2,john,doe,htw,2000,devHere is the code:from iter…

Unable to submit Spark job from Windows IDE to Linux cluster

I just read about findspark and found it quite interesting, as so far I have only used spark-submit which isnt be suited for interactive development on an IDE. I tried executing this file on Windows 10…

Updating variable values when running a thread using QThread in PyQt4

So problem occurred when I tried using Threading in my code. What I want to do is passing default values to the def __init__ and then calling the thread with its instance with updated values but someho…

Show terminal status in a Tkinter widget

I am using python2.7.10 on MacOs Sierra and have created a rsync over ssh connection with my raspberrypi. The Idea is to synchronize my local folder with my remote folder on the raspberrypi. My functio…