Deleting a parent document with no Child Documents


(Ishan Durugkar) #1

Hi,

I am new to elasticsearch. I was trying to create a parent-child mapping
where the children would be frequently added and removed.
Every Parent should have at least one child.

What I want to do is, if a child is deleted, I want to check if the parent
has other children documents, and if not, delete that parent document.
How do I do this?

I was trying a delete by query, but I am not sure which query I should send.

Thanks for the help! :slight_smile:

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/282aca7b-4b38-41ab-91c5-42094083d8d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Hannes Korte) #2

Hi Ishan,

I usually do that using a query like this:

{
"query" : {
"constant_score" : {
"filter" : {
"not" : {
"filter" : {
"has_parent" : {
"query" : {
"match_all" : { }
},
"parent_type" : "### PARENT TYPE ###"
}
}
}
}
}
}
}

Good luck! Better test the query before deleting! :wink:

Best regards,
Hannes

On 23.05.2014 13:03, Ishan Durugkar wrote:

Hi,

I am new to elasticsearch. I was trying to create a parent-child mapping
where the children would be frequently added and removed.
Every Parent should have at least one child.

What I want to do is, if a child is deleted, I want to check if the parent
has other children documents, and if not, delete that parent document.
How do I do this?

I was trying a delete by query, but I am not sure which query I should send.

Thanks for the help! :slight_smile:

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/538080FE.70603%40hkorte.com.
For more options, visit https://groups.google.com/d/optout.


(Ishan Durugkar) #3

Hi Hannes,

I actually wanted to find parent with no child, but I modified your query
accordingly and it is working!

Thanks! :slight_smile:
Ishan

On Saturday, May 24, 2014 4:52:56 PM UTC+5:30, Hannes Korte wrote:

Hi Ishan,

I usually do that using a query like this:

{
"query" : {
"constant_score" : {
"filter" : {
"not" : {
"filter" : {
"has_parent" : {
"query" : {
"match_all" : { }
},
"parent_type" : "### PARENT TYPE ###"
}
}
}
}
}
}
}

Good luck! Better test the query before deleting! :wink:

Best regards,
Hannes

On 23.05.2014 13:03, Ishan Durugkar wrote:

Hi,

I am new to elasticsearch. I was trying to create a parent-child mapping
where the children would be frequently added and removed.
Every Parent should have at least one child.

What I want to do is, if a child is deleted, I want to check if the
parent
has other children documents, and if not, delete that parent document.
How do I do this?

I was trying a delete by query, but I am not sure which query I should
send.

Thanks for the help! :slight_smile:

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/e42da428-4d9e-4d64-a094-2d0d06c3077f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4