# Deleting a child mapping affects querying other children of the same parent

**URL:** <https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738>\
**Category:** Elasticsearch\
**Created:** [September 22, 2015, 3:21am UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738 "2015-09-22T03:21:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmager](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmager/32/4908_2.png) [@jmager](https://discuss.elastic.co/u/jmager)\
**Post date:** [September 22, 2015, 3:21am UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/1 "2015-09-22T03:21:40Z")

</div>

Hi all,

recently I came across the problem, described in this post:  
[Delete one child type mapping, affected other children queries](https://discuss.elastic.co/t/delete-one-child-type-mapping-affected-other-children-queries/22390)

Unfortunately, there were no replies or comments there. That is why I'll describe the problem once more.  
I used the examples provided in the article:  
[Fun With Elasticsearch's Children and Nested Documents](http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/)

I've created an "authors" index and added 2 documents to the "bare\_author" type, with the help of:

```
curl -XPUT localhost:9200/authors/bare_author/1 -d'{"name": "Multi G. Enre"}'
curl -XPUT localhost:9200/authors/bare_author/2 -d'{"name": "Alastair Reynolds"}'

```

Then specified the parent-child relation:

```
curl -XPOST localhost:9200/authors/book/_mapping -d $'{\n "book":{\n "_parent": {"type": "bare_author"}\n }\n}'

```

Added 3 documents to the "book" mapping:

```
curl -XPOST localhost:9200/authors/book/1?parent=2 -d $'{\n "name": "Revelation Space",\n "genre": "scifi",\n "publisher": "penguin"\n}'
curl -XPOST localhost:9200/authors/book/2?parent=1 -d $'{\n "name": "Guns and lasers",\n "genre": "scifi",\n "publisher": "orbit"\n}'
curl -XPOST localhost:9200/authors/book/3?parent=1 -d $'{\n "name": "Dead in the night",\n "genre": "thriller",\n "publisher": "penguin"\n}'

```

Specified another parent-child relation:

```
curl -XPOST localhost:9200/authors/magazine/_mapping -d $'{\n "magazine":{\n "_parent": {"type": "bare_author"}\n }\n}'

```

Added 2 documents to the second type:

```
curl -XPOST localhost:9200/authors/magazine/1?parent=1 -d $'{\n "name": "Fun with Elasticsearch",\n "genre": "blogging",\n "article": "Parent and Child"\n}'
curl -XPOST localhost:9200/authors/magazine/2?parent=2 -d $'{\n "name": "You Know, for Search",\n "genre": "analytic",\n "article": "Managing Relations"\n}'

```

Up to this moment all goes well. I'm able to query both children types.  
Used this query (via elasticsearch \_plugin/head):  
[http://localhost:9200/authors/book/](http://localhost:9200/authors/book/)  
\_search

```
{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": {
            "has_parent": {
              "query": {
                "ids": {
                  "type": "bare_author",
                  "values": [
                    "2"
                  ]
                }
              },
              "parent_type": "bare_author"
            }
          }
        }
      }
    }
  },
  "explain": false,
  "fields": [
    "_parent",
    "_source"
  ]
}

```

to find a book of the author with id=2.

If I now delete the "magazine" type:

```
curl -XDELETE localhost:9200/authors/magazine

```

I'm not able to make any other child queries. Even the one given above, results in: 3 shards return no matches, 2 shards return:

```
"status": 500,
"reason": "QueryPhaseExecutionException[[authors][2]: query[filtered(ConstantScore(BooleanFilter(+CustomQueryWrappingFilter(parent_filter[bare_author](filtered(ConstantScore(_uid:bare_author#2))->cache(_type:bare_author))))))->cache(_type:book)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: RuntimeException[java.lang.NullPointerException]; nested: NullPointerException; "

```

Like the author of the previous discussion mentioned, restarting the Elasticsearch helps.

Would appreciate any help, ideas, experience.  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 23, 2015, 2:30am UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/2 "2015-09-23T02:30:55Z")

</div>

What version are you on?

---

<div class="post-metadata">

**Author:** ![jmager](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmager/32/4908_2.png) [@jmager](https://discuss.elastic.co/u/jmager)\
**Post date:** [September 23, 2015, 4:41am UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/3 "2015-09-23T04:41:48Z")

</div>

Hi, Warkolm! Thanks for your reply!

Sorry, I forgot to clarify that part.  
Elasticsearch 1.7.2.  
Here is more detailed info from \_plugin/head:  
"version" : {  
"number" : "1.7.2",  
"build\_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",  
"build\_timestamp" : "2015-09-14T09:49:53Z",  
"build\_snapshot" : false,  
"lucene\_version" : "4.10.4"  
}

Runs on Ubuntu, if this somehow matters.

---

<div class="post-metadata">

**Author:** ![jmager](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmager/32/4908_2.png) [@jmager](https://discuss.elastic.co/u/jmager)\
**Post date:** [September 23, 2015, 5:21am UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/4 "2015-09-23T05:21:41Z")

</div>

Thought that this may make something clear for people, with more experience than me 😄  
Here is what could be found in log files:

```
[2015-09-21 13:09:17,382][INFO][cluster.metadata] [Airstrike] [[authors]] remove_mapping [[magazine]]
[2015-09-21 13:10:04,671][DEBUG][action.search.type] [Airstrike] [authors][2], node[FupU8MLoTYuFz-ieKa1Qhg], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@68991775] lastShard [true]
org.elasticsearch.search.query.QueryPhaseExecutionException: [authors][2]: query[filtered(ConstantScore(BooleanFilter(+CustomQueryWrappingFilter(parent_filter[bare_author](filtered(ConstantScore(_uid:bare_author#2))->cache(_type:bare_author))))))->cache(_type:book)],from[0],size[10]: Query Failed [Failed to execute main query]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:163)
	at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:301)
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:312)
	at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
	at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
	at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
	at org.elasticsearch.search.internal.ContextIndexSearcher.createNormalizedWeight(ContextIndexSearcher.java:136)
	at org.elasticsearch.index.search.child.CustomQueryWrappingFilter.getDocIdSet(CustomQueryWrappingFilter.java:72)
	at org.elasticsearch.common.lucene.search.XBooleanFilter.getDocIdSet(XBooleanFilter.java:59)
	at org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter.getDocIdSet(ApplyAcceptedDocsFilter.java:46)
	at org.apache.lucene.search.ConstantScoreQuery$ConstantWeight.scorer(ConstantScoreQuery.java:157)
	at org.apache.lucene.search.FilteredQuery$RandomAccessFilterStrategy.filteredScorer(FilteredQuery.java:542)
	at org.apache.lucene.search.FilteredQuery$FilterStrategy.filteredBulkScorer(FilteredQuery.java:504)
	at org.apache.lucene.search.FilteredQuery$1.bulkScorer(FilteredQuery.java:150)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:618)
	at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:191)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:157)
	... 8 more
Caused by: java.lang.NullPointerException
	at org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData$GlobalAtomicFieldData.getOrdinalsValues(ParentChildIndexFieldData.java:353)
	at org.elasticsearch.index.search.child.ParentConstantScoreQuery.createWeight(ParentConstantScoreQuery.java:97)
	at org.apache.lucene.search.IndexSearcher.createNormalizedWeight(IndexSearcher.java:684)
	at org.elasticsearch.search.internal.ContextIndexSearcher.createNormalizedWeight(ContextIndexSearcher.java:133)
	... 22 more
[2015-09-21 13:10:04,671][DEBUG][action.search.type] [Airstrike] [authors][3], node[FupU8MLoTYuFz-ieKa1Qhg], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@68991775]
org.elasticsearch.search.query.QueryPhaseExecutionException: [authors][3]: query[filtered(ConstantScore(BooleanFilter(+CustomQueryWrappingFilter(parent_filter[bare_author](filtered(ConstantScore(_uid:bare_author#2))->cache(_type:bare_author))))))->cache(_type:book)],from[0],size[10]: Query Failed [Failed to execute main query]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:163)
	at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:301)
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:312)
	at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
	at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
	at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
```

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [September 23, 2015, 1:06pm UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/5 "2015-09-23T13:06:05Z")

</div>

This is a bug. It has been fixed in 2.0.0-beta2. The fix can be backported to 1.7, but not sure if there will be a 1.7 release soon.

---

<div class="post-metadata">

**Author:** ![jmager](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmager/32/4908_2.png) [@jmager](https://discuss.elastic.co/u/jmager)\
**Post date:** [September 24, 2015, 8:39am UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/6 "2015-09-24T08:39:34Z")

</div>

Hi mvg, thank you very much for clarifying that!  
And special thanks for the quick reply! 😄  
Is there any information available about the release date of 2.0.0 as a stable release?

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [September 25, 2015, 8:32am UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/7 "2015-09-25T08:32:23Z")

</div>

There is no hard date for when a stable release goes out. First a RC release goes out and if all goes well then the GA release goes out. I expect a RC release relatively soon.

---

<div class="post-metadata">

**Author:** ![bigjocker](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@bigjocker](https://discuss.elastic.co/u/bigjocker)\
**Post date:** [February 18, 2016, 8:05pm UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/8 "2016-02-18T20:05:47Z")

</div>

If I'm reading correctly, this is a bug that was fixed in 2.x. But not really, since parent-child was redesigned in 2.0 and does not work like in the example shown here: in 2.x parents and child must be created in the same call, so it's actually a new form of nested ... you just removed parent-child feature entirely:

[https://www.elastic.co/guide/en/elasticsearch/reference/2.0/breaking\_20\_parent\_child\_changes.html#\_parent\_type\_cannot\_pre\_exist](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/breaking_20_parent_child_changes.html#_parent_type_cannot_pre_exist)

Is there any plan to backport the fix to this bug to 1.7? Since our application relies on the _real_ parent-child relationship (parents are created ahead of time, child is created referencing the parent, a relationship instead of nesting documents) we can't move to 2.x until we refactor everything.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:15pm UTC](https://discuss.elastic.co/t/deleting-a-child-mapping-affects-querying-other-children-of-the-same-parent/29738/9 "2017-07-05T23:15:09Z")

</div>


