Deleting Record from ES


(Siv) #1

Hi

I have indexed data in Elastic Search as

{"_index":"school","_type":"student","_id":"AVHKjoOLfAoTEUc3htss","_score":1.0,"_source":{
"schoolId" : "1952",
"studentId" : "1053",
"createdDate" : "2009-11-15T14:12:12" ,
"updatedDate" : "2009-11-15T14:12:12",
"location": {
"lat": 41.12,
"lon": -71.34
}
}

I'm trying to delete the above record using

http://localhost:9400/schoolId/_query

{"query" : {
"term" : { "schoolId" : "1952" }
}}

but it is not removing that particular record (schoolId is Unique). However, If I use the below query it removes.

http://localhost:9400/schoolId/_query

{"query" : {
"term" : { "_id" : "AVHKjoOLfAoTEUc3htss" }
}}

Is there anything wrong in my first query.


(Kartheek Gummaluri) #2

Yes,actually you are trying using wrong syntax.

curl -XGET 'http://localhost:9200/school/student/_delete
{
"_id" : "AVHKjoOLfAoTEUc3htss"
}


(Siv) #3

It is not working also I want to use "schoolId" as parameter not _id to delete the document.


(David Pilato) #4

TBH you should better use your schoolId as the document id. It will be more efficient for updates/removes/get...


(Siv) #5

YES that works fine. Just in case if I have to more constraints what should I do ? I tried the below but didnt work.

{"query" : {
"and" : [
{"term" : { "_id" : "1952" }},
{"term" : { "studentId" : "1053" }}]
}
}


(Siv) #6

Got it working !! Thank You.


(system) #7